Check given PHAsset is iCloud asset?

后端 未结 6 1181
再見小時候
再見小時候 2021-02-02 14:16

I\'m trying to get PhAsset object. I want to segregate iCloud assets. Here is my code,

PHFetchResult *cloudAlbums = [PHAssetCollection fetchAssetCollectionsWithT         


        
6条回答
  •  终归单人心
    2021-02-02 14:55

    When you request for an image you get a key in info dictionary which tells you if the asset is present in iCloud.

    [cloudAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop)
    {
        PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:collection options:fetchOptions];
        [result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop)
        {  
            PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
            options.resizeMode = PHImageRequestOptionsResizeModeFast;
            options.synchronous = YES;
            __block BOOL isICloudAsset = NO;
            [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage *result, NSDictionary *info) 
            {
                if ([info objectForKey: PHImageResultIsInCloudKey].boolValue) 
                {
                    isICloudAsset = YES;
                }
            }]; 
        }];
    }];
    

提交回复
热议问题