【发布时间】:2020-06-07 21:21:32
【问题描述】:
我已经构建了一个 iOS 应用程序,它将图像从 UIImageView 保存到用户的照片库。 这适用于 iOS,但是当我尝试在 iOS 13/macOS Catalina 中使用 Apple 的 Mac Catalyst 产品向此应用添加对 Mac 的支持时,图像无法保存,并且显示一条错误消息。
我用来保存照片的代码复制如下:
@objc func export(sender:AnyObject) {
UIImageWriteToSavedPhotosAlbum(self.previewImageView.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if let error = error {
print("Error saving: \(error)")
let ac = UIAlertController(title: "Save error", message: error.localizedDescription, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
} else {
let ac = UIAlertController(title: "Saved", message: "Your image has been saved to your photos.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
}
}
警报视图中的错误消息是“未知错误”,但这是在 Xcode 控制台中打印的错误消息:
[GatekeeperXPC] XPC connection error to assetsd getSystemLibraryURLReadOnlyServiceWithReply: : Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.photos.service was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.photos.service was invalidated.}
Error saving: Error Domain=ALAssetsLibraryErrorDomain Code=-1 "Unknown error" UserInfo={NSLocalizedDescription=Unknown error, NSUnderlyingError=0x600000cfe4f0 {Error Domain=ALAssetsLibraryErrorDomain Code=-1 "Unknown error" UserInfo={NSLocalizedDescription=Unknown error, NSUnderlyingError=0x600000d01680 {Error Domain=ALAssetsLibraryErrorDomain Code=-1 "Unknown error" UserInfo={NSLocalizedDescription=Unknown error, NSUnderlyingError=0x600000d03930 {Error Domain=com.apple.photos.error Code=41002 "Unable to obtain photolibraryd XPC proxy for getResourceWriteOnlyServiceWithReply:. photolibraryd could have crashed" UserInfo=0x6000017be600 (not displayed)}}}}}}
您知道为什么会发生此错误吗?我是否可以采取任何措施来获取有关如何修复此错误的更多信息或其他我可以尝试的方法?
谢谢。
【问题讨论】:
-
您的应用占用了大量内存?
-
我得到了完全相同的错误。你找到解决办法了吗?谢谢。
-
@stefat 请看下面复制的答案。
-
你找到答案了吗?就我而言,我有一个可以运行的应用程序,而另一个没有(并且像您的一样崩溃),使用与您相同的例程。
标签: ios swift macos uiimage mac-catalyst