iOS11 camera flashback, save image flashback problem (solved)

Problem Description

There is a bug in the project recently, and the mobile phone that upgrades the iOS11 system will flash back when using our app to save pictures to the album or take pictures.
After some searching, I found that it was caused by the following code:
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

problem solved

  1. At first, I thought that the calling method of the function had changed, but if it is called in different places, or different parameters are passed in, it will still flash back;
  2. After some debugging, it was found that such an error message that did not appear during the crash would appear when it crashed:

    This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.

  3. According to the error message, after adding the NSPhotoLibraryAddUsageDescription attribute to the plist file, the crash problem no longer occurs.

problem causes


  1. After solving the problem, I looked up the Apple development documentation, the official documentation is described as follows:

NSPhotoLibraryAddUsageDescription
NSPhotoLibraryAddUsageDescription (String - iOS) This key lets you describe the reason your app seeks write-only access to the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.
Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and that accesses the user’s photo library, must statically declare the intent to do so. Include the NSPhotoLibraryAddUsageDescription key (in apps that link on or after iOS 11) or NSPhotoLibraryUsageDescription key in your app’s Info.plist file and provide a purpose string for the key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits.
This key is supported in iOS 11.0 and later.
Source: Official Documentation

This is a new permission in the iOS11 version, which needs to be added when saving pictures to the album.
2. Due to the lack of official explanations, I searched for other information on the Internet:

Before iOS11:
NSPhotoLibraryUsageDescription: When accessing albums and storing photos to albums (read and write), user authorization will appear.
After iOS11:
NSPhotoLibraryUsageDescription: No need to add. By default, the permission to access the album (read) is enabled, and no user authorization is required.

NSPhotoLibraryAddUsageDescription: Add content to album (write), user authorization will appear.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326846542&siteId=291194637