即使我没有将照片保存在任何地方,但每当我在didFinishPickingMediaWithInfo
功能中访问已编辑的图像时,iOS都会要求我允许访问设备上的照片。
知道如何阻止它获得许可。
添加UIImagePickerController
- (IBAction)addPhotoButtonPressed:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
[self presentViewController:picker animated:YES completion:NULL];
}
didFinishPickingMediaWithInfo
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image;
image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
if (image == nil)
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
NSData *imageData = UIImageJPEGRepresentation(image, 0.05f);
_locationImage.image = [UIImage imageWithData:imageData];
imageFile = [PFFile fileWithName:@"Image.jpg" data:imageData];
}
答案 0 :(得分:3)
我没有看到任何羞于编写自己的编辑控件的方法(虽然这并不难)然后你就完全掌控了。
UIImagePicker要求 - 我猜 - 因为它会暂时保存原始图像,就像它确实被保存一样......
答案 1 :(得分:0)
您必须知道,首次访问照片库时,必须向用户提供权限。
您必须通过
检查权限AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusAuthorized) {
// do your logic
} else if(authStatus == AVAuthorizationStatusDenied){
// denied
} else if(authStatus == AVAuthorizationStatusRestricted){
// restricted, normally won't happen
} else if(authStatus == AVAuthorizationStatusNotDetermined){
// not determined?!
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
if(granted){
NSLog(@"Granted access to %@", mediaType);
} else {
NSLog(@"Not granted access to %@", mediaType);
}
}];
} else {
// impossible, unknown authorization status
}