iOS 10 app crashes when trying to save image to photo library
<p>I'm trying to save an image to the photo library in Swift 3 (I'm working with Xcode 8).</p>

<p>ViewController Code:</p>

<pre><code>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)
}
</code></pre>

<p>When I run the application, and click on the button to take the screenshot (converting it to image, ..., that's all working perfectly), the app asks for permission to access the photo library, I tap the "OK" button, and then the app crashes. The image is not saved in the photo library.</p>

<p>The only clue I get from Xcode is the following:</p>

<pre><code>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 &lt;private&gt;, cannot attempt migration &lt;private&gt;)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store &lt;private&gt;.  Requires update via assetsd (256: &lt;private&gt;)
</code></pre>

<p>Does anyone have any idea how to fix this?</p>

<p>Thanks in advance!  </p>

<p><strong>UPDATE</strong></p>

<p>Sharing the image on Social Media works fine, so the problem is specified to saving the image in the photo library.</p>