如何解决Mac Catalyst 无法在相册中保存图像,但未产生错误
我正在将应用程序移植到 Catalyst。该应用程序具有在 Catalyst 环境中将屏幕截图保存到命名相册的功能,在直接 iOS 中保存到相机胶卷。代码运行良好,并产生一个没有错误的“成功”代码。如果我查看收藏的估计资产数量,每次尝试后都会增加。但是,在“照片”应用程序中查看时,相册中没有内容。 我的屏幕截图在哪里? 相关代码如下:
func insertimage(image : UIImage,intoAssetCollection collection : PHAssetCollection) {
PHPhotoLibrary.shared().performChanges({
let creationRequest = PHAssetCreationRequest.creationRequestForAsset(from: image)
let request = PHAssetCollectionChangeRequest(for: collection)
if request != nil && creationRequest.placeholderForCreatedAsset != nil {
request!.addAssets([creationRequest.placeholderForCreatedAsset!] as NSFastEnumeration)
}
},completionHandler: { (success,error) in
if error != nil {
print("Error: " + error!.localizedDescription)
dispatchQueue.main.async {
let ac = UIAlertController(title: "Save error",message: error!.localizedDescription,preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "Done",style: .default))
self.present(ac,animated: true)
}
} else {
dispatchQueue.main.async {
let ac = UIAlertController(title: "Save success",message: "Image saved",animated: true)
}
}
}
)
专辑收藏来自:
func fetchAssetCollectionWithAlbumName(albumName : String) -> PHAssetCollection? {
let fetchOption = PHFetchOptions()
fetchOption.predicate = nspredicate(format: "title == '" + albumName + "'")
let fetchResult = PHAssetCollection.fetchAssetCollections(
with: PHAssetCollectionType.album,subtype: PHAssetCollectionSubtype.albumRegular,options: fetchOption)
let collection = fetchResult.firstObject
return collection
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。