Swift 3 のフォト ライブラリに画像を保存しようとしています (Xcode 8 を使用しています)。
ViewController コード:
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)
}
アプリケーションを実行し、ボタンをクリックしてスクリーンショットを撮ります (画像に変換する...、それはすべて完全に機能しています)。アプリは写真ライブラリへのアクセス許可を求めます。[OK] ボタンをタップします。その後、アプリがクラッシュします。画像はフォト ライブラリに保存されません。
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>)
誰でもこれを修正する方法を知っていますか?
前もって感謝します!
アップデート
ソーシャル メディアでの画像の共有は正常に機能するため、問題は画像をフォト ライブラリに保存することです。