似乎大多数方法指向UIImageWriteToSavedPhotosAlbum()
,但在iOS 6及更高版本中,您需要用户权限才能写入相机胶卷,因此如果他们说“不”,我希望能够调用代码。
是否有基于块的方法允许我在“失败”时调用代码?
答案 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
}
}