Skip to content

PHPhotoLibrary.requestAuthorizationForAccessLevel() static method ​

The PHPhotoLibrary.requestAuthorizationForAccessLevel() static method requests photo library permission.

Syntax ​

PHPhotoLibrary.requestAuthorizationForAccessLevel(accessLevel)

Parameters ​

accessLevel

Only one value, 'addOnly': permission to add to the library.

Return value ​

A Promise that resolves to the authorization status; for the values, see Authorization status.

  • When the user hasn't been asked yet, the system shows a prompt, and the Promise resolves after the user taps. The prompt's text is the NSPhotoLibraryAddUsageDescription written in nacre.config.json.
  • Once asked, no prompt is shown again; it resolves directly to the current status.

When the project doesn't have NSPhotoLibraryAddUsageDescription, the Promise is rejected with name InvalidStateError. This doesn't happen with projects generated by the CLI, which stops at generation.

The prompt and the resolved result are not verified in the simulator.

Exceptions ​

TypeError

An invalid accessLevel, thrown synchronously rather than rejecting the Promise. The error is the same as for authorizationStatusForAccessLevel().

Description ​

You don't need to call it before saving: performChanges() requests permission itself first when the user hasn't been asked.

Examples ​

js
const status = await PHPhotoLibrary.requestAuthorizationForAccessLevel('addOnly');
console.log(status);

Effect (not verified in the simulator): On the first call, a prompt is shown. Tapping "Allow" prints authorized; tapping "Don't Allow" prints denied. Later calls don't prompt and print the current status directly.

Corresponding iOS API ​

+[PHPhotoLibrary requestAuthorizationForAccessLevel:handler:]. The callback is replaced by a Promise.

See also ​