【问题标题】:How do you save an image to the camera roll/photos album in iOS 6/7?如何在 iOS 6/7 中将图像保存到相机胶卷/相册?
【发布时间】:2014-02-08 02:11:07
【问题描述】:

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

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

【问题讨论】:

  • 该函数的第三个参数是completionSelector,如果失败会调用。

标签: ios objective-c cocoa-touch uiimage


【解决方案1】:

检查一下

/* 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
}
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    相关资源
    最近更新 更多