拿起图像后,我想删除photoStore中的照片。出于想法noew

时间:2016-02-17 20:59:40

标签: ios iphone swift ios7

for asset in assets{
            let phasest =  asset.originalAsset
          print(phasest?.mediaType)
          let currentPhasset =  PHAsset.fetchAssetsWithMediaType(phasest?.mediaType, options: nil)
            asset.fetchFullScreenImageWithCompleteBlock({ (image, info) -> Void in
                orignalImages.append(image!)
                print (info)
                let fetchResult = currentPhasset

                    let lastAsset: PHAsset = fetchResult[1] as! PHAsset
                    print(fetchResult)
                   let arrayToDelete = NSArray(object: lastAsset)
                    PHPhotoLibrary.sharedPhotoLibrary().performChanges( {
                        PHAssetChangeRequest.deleteAssets(arrayToDelete)},
                        completionHandler: {
                            success, error in
                            NSLog("Finished deleting asset. %@", (success ? "Success" : error!))

                    }) 

我使用dkimagecontroller来选择图像。在我的代码中我可以删除第一张照片,因为我在获取结果中传递索引1。如果我传递任何更大的数字,它将删除空数据。那么如何删除所选图像?我

1 个答案:

答案 0 :(得分:0)

好吧。我发现很容易解决这个问题。希望它可以帮助某人

for asset in assets{
            let phasest =  asset.originalAsset
            asset.fetchFullScreenImageWithCompleteBlock({ (image, info) -> Void in
                orignalImages.append(image!)
                if (phasest != nil) {
                let arrayToDelete = NSArray(object: phasest!)
                PHPhotoLibrary.sharedPhotoLibrary().performChanges( {
                        PHAssetChangeRequest.deleteAssets(arrayToDelete)},
                        completionHandler: {
                            success, error in
                            NSLog("Finished deleting asset. %@", (success ? "Success" : error!))

                    }) 

                }