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(@"无法打开短信功能");
}
- (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];