照相机,短信、邮件、加速剂

UIImagePickerControllerSourceType有三个类型

UIImagePickerControllerSourceTypePhotoLibrary

UIImagePickerControllerSourceTypeCamera

UIImagePickerControllerSourceTypeSavedPhotosAlbum


使用照相机前要判断设备是否有照相机,使用isSourceTypeAvailable方法


使用的时候一般定义其delegate,sourceType,allowEditing,注意它的代理有两个UINavigationControllerDelegate和UIImagePickerControllerDelegate


代理方法中- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info,注意其中info是一个字典


使用中要记得[[self presentModalViewController:picker animated:YES];

使用后要记得[self dismissModalViewControllerAnimated:YES];




短信和邮件要引入类库MessageUI.framework以及相应的头文件,注意代理是MFMessageComposeViewControllerDelegate和MFMailComposeViewControllerDelegate


注意这两个都分程序内还是程序外打开,也要先判断是否canSenText,使用的是MFMessageComposeViewController

短信功能的时候需要设置的属性或者方法一般有body,recipients,messageComposeDelegate



使用中要记得[[self presentModalViewController:picker animated:YES];

使用后要记得[self dismissModalViewControllerAnimated:YES];


程序外打开设置URL,也需要先判断是否能打开这个地址,如:

 NSURL *numberURL = [NSURL URLWithString:[NSString stringWithFormat:@"sms:1360001234"]];

    //判断程序是否可以打开短信功能

    if ([[UIApplication sharedApplication] canOpenURL:numberURL]) 

    {

        [[UIApplication sharedApplication] openURL:numberURL];

    } else

    {

        NSLog(@"无法打开短信功能");

    }


邮件稍微复杂一点,需要设置 setSubject,setToRecipients,setCcRecipients,setMessageBody,setMailComposeDelegate.其次就是实现代理方法,比如


- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error


{

    switch (result) {

        case MFMailComposeResultCancelled:

            //取消发送

            NSLog(@"Result: canceled");

            break;

        case MFMailComposeResultSent:

            //发送

            NSLog(@"Result: Sent");

            break;

        case MFMailComposeResultFailed:

            //发送失败

            NSLog(@"Result: Failed");

            break;

        case MFMailComposeResultSaved:

            //保存

            NSLog(@"Result: Saved");

            break;

        default:

            break;

    }

    [self dismissModalViewControllerAnimated:YES];

}



加速剂需要使用代理UIAccelerometerDelegate,需要设置的方法或者属性一般有sharedAccelerometer,setUpdateInterval,delegate.如:

// 设置加速计采集频率(单位:)

[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0 / 60.0];

// 设置委托(注意对象销毁时要将委托设置为空)

    [[UIAccelerometer sharedAccelerometer] setDelegate:self];


注意完成之后需要把代理设置为nil,如:


[[UIAccelerometer sharedAccelerometer] setDelegate:nil];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值