尝试将图像保存到图片库时,iOS 10应用程序崩溃 [英] iOS 10 app crashes when trying to save image to photo library

查看:54
本文介绍了尝试将图像保存到图片库时,iOS 10应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像保存到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>)

有人知道如何修复此问题吗?

提前谢谢!

更新

在社交媒体上共享图像工作正常,因此指定的问题是将图像保存在照片库中。

推荐答案

将新记录添加到新的InfoPlist.string文件中。

<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME)</string>

更新:iOS 11密钥

这篇关于尝试将图像保存到图片库时,iOS 10应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆