本文介绍了将照片保存到相机胶卷并确保其实际保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正以这种方式将UIImage保存到相机胶卷。
I am currently saving a UIImage to the camera roll this way.
UIImageWriteToSavedPhotosAlbum(finalPicture.image,nil,nil,nil);
但是,如果用户拒绝我们访问他们的照片的权限会发生什么...我怎么能知道这已经发生并显示错误消息?
But what happens if the user denies us permission to access their photos... how can I tell that this has happened and display an error message?
推荐答案
要将图像保存到相机胶卷,我在方法中使用ALAssetsLibrary:
To save the image to the camera roll I'm Using ALAssetsLibrary so in the method:
//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
}
还记得你必须先检查相机是否可用。
Also remember that you have to check first if the camera is available.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
//The camera is available
}else{
//No camera available
}
这篇关于将照片保存到相机胶卷并确保其实际保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!