gpt4 book ai didi

ios - 删除 PHAssetCollection (Swift)

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:45 24 4
gpt4 key购买 nike

我创建了一个 PHAssetCollection 来为我的应用程序存放我的照片,它工作正常。但是,我试图拥有它,以便用户可以在按下按钮时删除 PHAssetCollection。如何删除我在以下代码中创建的整个 AssetCollection(“应用程序文件夹”)?



创建 PHAssetCollection 的代码:

    let albumName = "App Folder" 

//Check if the folder exists, if not, create it
let fetchOptions = PHFetchOptions()
fetchOptions.predicate = NSPredicate(format: "title = %@", albumName)
let collection:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(.Album, subtype: .Any, options: fetchOptions)

if let first_Obj:AnyObject = collection.firstObject{
//found the album
self.albumFound = true
self.assetCollection = first_Obj as! PHAssetCollection
}else{
//Album placeholder for the asset collection, used to reference collection in completion handler
var albumPlaceholder:PHObjectPlaceholder!
//create the folder
NSLog("\nFolder \"%@\" does not exist\nCreating now...", albumName)
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let request = PHAssetCollectionChangeRequest.creationRequestForAssetCollectionWithTitle(albumName)
albumPlaceholder = request.placeholderForCreatedAssetCollection
},
completionHandler: {(success:Bool, error:NSError!)in
if(success){
println("Successfully created folder")
self.albumFound = true
if let collection = PHAssetCollection.fetchAssetCollectionsWithLocalIdentifiers([albumPlaceholder.localIdentifier], options: nil){
self.assetCollection = collection.firstObject as! PHAssetCollection
}
}else{
println("Error creating folder")
self.albumFound = false
}
})

}

最佳答案

    PHPhotoLibrary.sharedPhotoLibrary().performChanges({ () -> Void in

PHAssetCollectionChangeRequest.deleteAssetCollections([self.deleteTarget])

}, completionHandler: nil)

关于ios - 删除 PHAssetCollection (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31371563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com