我目前正在以这种方式将 UIImage 保存到相机胶卷中。
UIImageWriteToSavedPhotosAlbum(finalPicture.image, nil, nil, nil);
但是如果用户拒绝我们访问他们的照片会发生什么......我怎么知道这已经发生并显示错误消息?
我目前正在以这种方式将 UIImage 保存到相机胶卷中。
UIImageWriteToSavedPhotosAlbum(finalPicture.image, nil, nil, nil);
但是如果用户拒绝我们访问他们的照片会发生什么......我怎么知道这已经发生并显示错误消息?
要将图像保存到相机胶卷,我正在使用 ALAssetsLibrary,因此在方法中:
//Called after taking the photo with the camera or selected the image from the gallery
- (void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSURL *referenceURL;
if(Picker.sourceType==UIImagePickerControllerSourceTypeCamera){
UIImage* takenImage=info[UIImagePickerControllerOriginalImage];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[takenImage CGImage] orientation:(ALAssetOrientation)[takenImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
//NOT SAVED
//DISPLAY ERROR THE PICTURE CAN'T BE SAVED
} else {
//SAVED
}
}];
}
}else{
//Selected from gallery
}
另请记住,您必须先检查相机是否可用。
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//The camera is available
}else{
//No camera available
}