在Safari8的Photos.framework中,我正在尝试将一个UIImage保存到用户的图片库中,这与在iOS中长按图像并选择“保存图像”的方式非常相似。在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);
}];我尝试访问“最近添加的”智能相册,但它不允许向其中添加新内容。
发布于 2014-11-14 01:54:38
你不需要和PHAssetCollection打交道。只需执行以下操作即可添加:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:<#your photo here#>];
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
<#your completion code here#>
}
else {
<#figure out what went wrong#>
}
}];发布于 2014-11-14 01:59:13
实际上,在8.1版本中,相机卷轴又回来了。它是子类型为SmartAlbumUserLibrary的智能相册。
https://stackoverflow.com/questions/26065774
复制相似问题