首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ALAssetsLibrary+CustomPhotoAlbum iOS 9

ALAssetsLibrary+CustomPhotoAlbum iOS 9
EN

Stack Overflow用户
提问于 2015-09-23 07:51:10
回答 1查看 1.5K关注 0票数 2

我更新了应用程序以支持iOS9,在iOS9中不再支持的AlAssets库出现错误,需要你PHPhotoLibrary。

请对更新代码以支持IOS 9所需的更改提出任何建议

代码语言:javascript
复制
   //
//  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
EN

回答 1

Stack Overflow用户

发布于 2015-09-24 17:17:06

ALAssetLibrary在iOS 9上被弃用,我认为它甚至在iOS 9上也不能正常工作,所以似乎ALAssets的访问在这里不再可用。

如果有人做了不同的体验,或者找到了解决办法,我会很感激。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32728877

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档