官方文檔地址:Camera and Photo
兩種方法:
- UIImagePickerController
- AV Foundation framework(暫時(shí)用不到)
UIImagePickerController
- info.plist中增加UIRequiredDeviceCapabilities
- 使用UIImagePickerController的isSourceTypeAvailable:方法判斷相機(jī)是否可用
- 實(shí)現(xiàn)delegate
Sample Codes
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
NSArray* availableTypes = [UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
if ([availableTypes containsObject:(NSString*)kUTTypeImage])
{
NSLog(@"Find target Media type.");
}
else
{
return NO;
}
cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString*)kUTTypeImage];
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
[self presentViewController:cameraUI animated:YES completion:nil];