我正在尝试将图像保存到 Swift 3 中的照片库(我正在使用 Xcode 8)。
视图控制器代码:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
当我运行应用程序,然后单击按钮截取屏幕截图(将其转换为图像,...,一切正常),应用程序请求访问照片库的权限,我点击“确定”按钮,然后应用程序崩溃。图像未保存在照片库中。
我从 Xcode 得到的唯一线索如下:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access file: 1} with userInfo dictionary {
reason = "Failed to access file: 1";
}
2016-09-28 11:24:27.216433 Ajax Kids[4143:1545362] [Migration] Unexpected error opening persistent store <private>, cannot attempt migration <private>)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store <private>. Requires update via assetsd (256: <private>)
有谁知道如何解决这个问题?
提前致谢!
更新
在社交媒体上共享图像工作正常,因此问题被指定为将图像保存在照片库中。