我更新了应用程序以支持iOS9,在iOS9中不再支持的AlAssets库出现错误,需要你PHPhotoLibrary。
请对更新代码以支持IOS 9所需的更改提出任何建议
//
// ALAssetsLibrary category to handle a custom photo album
//
// Created by Marin Todorov on 10/26/11.
// Copyright (c) 2011 Marin Todorov. All rights reserved.
//
#import "ALAssetsLibrary+CustomPhotoAlbum.h"
@implementation ALAssetsLibrary(CustomPhotoAlbum)
-(void)saveImage:(UIImage*)image toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
//write the image data to the assets library (camera roll)
[self writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation
completionBlock:^(NSURL* assetURL, NSError* error) {
//error handling
if (error!=nil) {
completionBlock(error,assetURL);
return;
}
//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
//search all photo albums in the library
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
//compare the names of the albums
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
//target album is found
albumWasFound = YES;
//get a hold of the photo's asset instance
[self assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
//add photo to the target album
[group addAsset: asset];
//run the completion block
completionBlock(nil,assetURL);
} failureBlock:^(NSError *error){ completionBlock(error,nil);}];
//album was found, bail out of the method
return;
}
if (group==nil && albumWasFound==NO) {
//photo albums are over, target album does not exist, thus create it
__weak ALAssetsLibrary* weakSelf = self;
//create new assets album
[self addAssetsGroupAlbumWithName:albumName
resultBlock:^(ALAssetsGroup *group) {
//get the photo's instance
[weakSelf assetForURL: assetURL
resultBlock:^(ALAsset *asset) {
//add photo to the newly created album
[group addAsset: asset];
//call the completion block
completionBlock(nil,assetURL);
} failureBlock: ^(NSError *error){ completionBlock(error,nil);}];
} failureBlock: ^(NSError *error){ completionBlock(error,nil);}];
//should be the last iteration anyway, but just in case
return;
}
} failureBlock: ^(NSError *error){ completionBlock(error,nil);}];
}
@end发布于 2015-09-24 17:17:06
ALAssetLibrary在iOS 9上被弃用,我认为它甚至在iOS 9上也不能正常工作,所以似乎ALAssets的访问在这里不再可用。
如果有人做了不同的体验,或者找到了解决办法,我会很感激。
https://stackoverflow.com/questions/32728877
复制相似问题