关于IOS某图片添加控件,图片从相册或拍照保存后,再次进入时点击放大图无法显示的问题

某图片添加控件:

https://github.com/XZTLLQ/LQPhotoPickerDemo

问题:

标题已说明

代码块:

NSArray *alAssetUrl =(NSMutableArray *)[HiddenRecordDataService getLocalImageSystemFilePath:_hiddenDangerInfoLocalModel.HiddenDangerInfoLocalId];
    NSMutableArray *localASSetArray = [NSMutableArray arrayWithCapacity:0];
    for (NSURL *url in alAssetUrl) {
        NSLog(@"url:%@", url);
        ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
        // library fetch
            [library assetForURL:url resultBlock:^(ALAsset *asset) {
                if (asset) {
                    [localASSetArray addObject:asset];
                } else {
                    // On iOS 8.1 [library assetForUrl] Photo Streams always returns nil. Try to obtain it in an alternative way
                }
            } failureBlock:^(NSError *error) {
                iToast *itoast = [iToast makeText:@"获取图片失败"];
                [itoast show];
            }];
    }

问题是由于标红代码导致,这里的ALAssetsLibrary对象需要用单例

代码如下:

 

NSArray *alAssetUrl =(NSMutableArray *)[HiddenRecordDataService getLocalImageSystemFilePath:_hiddenDangerInfoLocalModel.HiddenDangerInfoLocalId];
    
    NSMutableArray *localASSetArray = [NSMutableArray arrayWithCapacity:0];
    
    for (NSURL *url in alAssetUrl) {
        NSLog(@"url:%@", url);
        //ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
        ALAssetsLibrary* library = [HiddenRecordViewController defaultAssetsLibrary];
//        library fetch
            [library assetForURL:url resultBlock:^(ALAsset *asset) {
                if (asset) {
                    [localASSetArray addObject:asset];
                } else {
                    // On iOS 8.1 [library assetForUrl] Photo Streams always returns nil. Try to obtain it in an alternative way
                }
                
            } failureBlock:^(NSError *error) {
                iToast *itoast = [iToast makeText:@"获取图片失败"];
                [itoast show];
            }];
        
    }
defaultAssetsLibrary代码:
+ (ALAssetsLibrary *)defaultAssetsLibrary {
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library;
}

 

 

 

posted on 2017-09-27 10:05  洛易  阅读(229)  评论(0编辑  收藏  举报