Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Mac Catalyst无法在相册中保存图像,但不会产生错误_Ios_Mac Catalyst_Phassetcollection - Fatal编程技术网

Ios Mac Catalyst无法在相册中保存图像,但不会产生错误

Ios Mac Catalyst无法在相册中保存图像,但不会产生错误,ios,mac-catalyst,phassetcollection,Ios,Mac Catalyst,Phassetcollection,我正在将一个应用程序移植到Catalyst。在Catalyst环境下,该应用程序具有将屏幕截图保存到命名相册的功能,在纯iOS环境下,该应用程序可将屏幕截图保存到相机滚动。该代码运行良好,生成的“成功”代码没有错误。如果我查看集合的估计资产数量,它会在每次尝试后增加。但是,在“照片”应用程序中查看时,相册中没有任何内容我的截图在哪里? 以下是相关代码: func insertImage(image : UIImage, intoAssetCollection collection : PHAss

我正在将一个应用程序移植到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", preferredStyle: .alert)
                    ac.addAction(UIAlertAction(title: "Done", style: .default))
                    self.present(ac, 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
}