ALAssetsLibrary invalid or null

2019-08-01 22:09发布

I get the following error message : invalid attempt to access <ALAssetPrivate: 0xa4a1ed0> past the lifetime of its owning ALAssetsLibrary when I try to create custom Image Picker.

I used this APPLE sample to create this app. The sample Apple app works perfectly. But when I copied that sample code to my app it get the above error message.

Please can someone help me why this error comes & ALAssetsGroup become null.

1条回答
乱世女痞
2楼-- · 2019-08-01 22:38

I found the answer for this problem. The problem is my ALAssetsLibrary I used got null by ARC. The solution is, add this static method instead of ALAssets Library..

+ (ALAssetsLibrary *)defaultAssetsLibrary {
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library; 
}

Source

查看更多
登录 后发表回答