美文网首页
iOS-删除最后一张图片

iOS-删除最后一张图片

作者: WhoJun | 来源:发表于2019-05-16 22:40 被阅读0次
       PHFetchResult *collectonResuts = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:[PHFetchOptions new]] ;
        [collectonResuts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            PHAssetCollection *assetCollection = obj;
            if (assetCollection.assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary)  {
                PHFetchOptions *options = [PHFetchOptions new];
                options.fetchLimit = 1;
                options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
                PHFetchResult *assetResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
    
                [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                    //获取相册的最后一张照片
                    if (assetResult.firstObject) {
                        [PHAssetChangeRequest deleteAssets:@[assetResult.firstObject]];
                    }
                } completionHandler:^(BOOL success, NSError *error) {
                    NSLog(@"Error: %@", error);
                }];
            }
        }];
    

    相关文章

      网友评论

          本文标题:iOS-删除最后一张图片

          本文链接:https://www.haomeiwen.com/subject/wtcgaqtx.html