Apple also urged developers to reflect on whether their apps really need so many album permissions. It is the responsibility of every developer to implement functions with the minimum permissions and protect user privacy.

Review album permissions

The access mode of album resources in iOS 14 is subdivided into writeOnly and readWrite. As a developer, we need to review the permissions required by the project.

If you are careful, you may notice that Apple does not provide readOnly permission. For apps that only need to read image resources, Apple recommends using the image picker provided with iOS 14 to select an image resource (iOS 14 corresponds below to UIImagePickerController). PHPicker has many advantages:

PHPicker is a standalone process and does not affect APP performance

The PHPicker does not require the user to grant permission to select resources owned by the user

PHPicker supports multiple selection

Here is a simple Demo:

The selection picture control appears as follows:

The PHPicker UI is fixed, so if you need to customize the UI, it’s recommended to call PhotoKit to implement the image selector yourself.

Write only Permission Write only permission means that the APP can only write to the album. The write permission popup is simpler than the read permission popup, with only allow and disallow options. Use a Demo to verify this:

First you need to configure the permission information under info.plist:

NSPhotoLibraryAddUsageDeion: when deposited in the photo album of the user information.

NSPhotoLibraryUsageDeion: Album access permission information. This parameter is mandatory; otherwise, the APP will Crash when accessing the album.

Using AssetsLibrary, PhotoKit and UIKit layer UIImageWriteToSavedPhotosAlbum (: : 🙂 write albums:

It is easy to find that using AssetsLibrary pops up Access permissions, which is not the independent popup claimed by Apple, and there is no system popup to select images after clicking select photos, but it can write to the album normally. PhotoKit and UIKit implemented as expected.

Read and write access

Compared with the write permission, the read permission is added. The permission configuration is the same as that of the write permission. Also use AssetsLibrary and PhotoKit respectively to read album resources, and the permissions of the two pop-ups show the same:

Select Limited Photo mode, PhotoKit access is normal, AssetsLibrary access is incorrect, apple did not match AssetsLibrary

The following error message is displayed:

Choose Full Photo mode and the two will behave the same.

AssetsLibrary adaptation

From the previous section, AssetsLibrary had problems with read and write permissions. Apple seems to have given up on maintaining AssetsLibrary, so it is recommended that those who are still using AssetsLibrary to manage resources migrate to PhotoKit as soon as possible.

Some non-negligible details

Most apis behave like Full Photo when the user selects Limited Photo mode, but there are a few apis that need to be noted:

Resources created using PHAssetCreationRequests are added to user-permitted collections by default

Unable to get or create albums

The photo album shared by user iCloud cannot be accessed

When the user selects Limited Photo mode, the APP will automatically pop up a selection of resources popup every time the user accesses PhotoKit for the first time:

This interaction mode is rather unfriendly to users, and the official advice is to turn off the automatic popup. An ideal interaction mode would be when the user selects Limited Photo mode, and the entry to modify the resource would be displayed in a specific interface (such as the Settings page), and a system popup would pop up when the user actively clicks on the entry.

First we need to shut down the system automatically popup window: in the Info. The file to add new key PHPhotoLibraryPreventAutomaticLimitedAccessAlert, set its value to YES:

Call PhotoKit API when the user clicks modify Resource entry to pop up the resource selection interface:

if dataSource? .count == 0 { if #available(iOS 14, *) { PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: weakSelf!) } else { // Fallback on earlier versions // let imagePickerController = UIImagePickerController() // imagePickerController.sourceType = .photoLibrary // // weakSelf! .present(imagePickerController, animated: true, completion: nil) }Copy the code