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

1 cocoa-touch objective-c uiimage ios

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

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

Paw*_*Rai 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
}
}
Run Code Online (Sandbox Code Playgroud)