在 iOS 8 的 Photos.framework 中,我试图将 UIImage 保存到用户的照片库中,就像在 Safari 中长按图像并选择“保存图像”一样。在 iOS 7 中,只需调用 ALAssetLibrary 的writeImageToSavedPhotosAlbum:metadata:completionBlock
.
对于 iOS 8,我们需要选择一个资产集合来添加一个 PHAsset,但我不知道哪个 PHAssetCollection 最接近保存到用户的“相机胶卷”(即使在 iOS 中真的没有8)
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *newAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
newAssetRequest.creationDate = time;
newAssetRequest.location = location;
PHObjectPlaceholder *placeholderAsset = newAssetRequest.placeholderForCreatedAsset;
PHAssetCollectionChangeRequest *addAssetRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:WHICH_ASSET_COLLECTION];
addAssetRequest addAssets:@[placeholderAsset];
} completionHandler:^(BOOL success, NSError *error) {
NSLog(@"Success: %d", success);
}];
我尝试访问“最近添加”智能相册,但它不允许向其中添加新内容。