如何将图像保存到iOS 6/7中的相机胶卷/相册?

时间:2014-02-08 02:11:07

标签: ios objective-c cocoa-touch uiimage

似乎大多数方法指向UIImageWriteToSavedPhotosAlbum(),但在iOS 6及更高版本中,您需要用户权限才能写入相机胶卷,因此如果他们说“不”,我希望能够调用代码。

是否有基于块的方法允许我在“失败”时调用代码?

1 个答案:

答案 0 :(得分:8)

检查这个

/* Save to the photo album */
UIImageWriteToSavedPhotosAlbum(imageToSave ,
                               self, // send the message to 'self' when calling the callback
                               @selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), // the selector to tell the method to call on completion
                               NULL); // you generally won't need a contextInfo here);

- (void)thisImage:(UIImage *)image hasBeenSavedInPhotoAlbumWithError:(NSError *)error usingContextInfo:(void*)ctxInfo {
if (error) {
    // Do anything needed to handle the error or display it to the user
} else {
    // .... do anything you want here to handle
    // .... when the image has been saved in the photo album
}
}