# When to call PHPhotoLibrary.register in iOS apps

Apple's PhotoKit framework allows app developers like you to access the photo and video assets managed by the Photos app.

![Apple](https://docs-assets.developer.apple.com/published/3459c84072/a27985f6-1ee8-4116-98c7-9199674be2df.png)

Using PhotoKit, you can fetch and cache assets for display and playback, edit image and video content, or manage collections of assets such as albums, Moments, and Shared Albums.

`PHPhotoLibrary` is the main API that allows you to
- retrieve or verify the user’s permission for your app to access Photos content
- make changes to assets and collections
- register for update messages the system sends when the library changes

The end-user has to grant permission to the app to access the photo library. This can be requested with static function  [`requestAuthorization(for:handler:)`](https://developer.apple.com/documentation/photokit/phphotolibrary/3616053-requestauthorization).

You can observe changes in the photo library and receive messages by registering an observer with the instance function  [`register(_:)`](https://developer.apple.com/documentation/photokit/phphotolibrary/1620741-register).

**Does it matter when to register for changes? 🤔**

It does since iOS 15.2 😊

In December 2021 an issue was observed when 
- using Xcode 13.2 and building on iOS 15.2 devices and
- installing the app for the 1st time on a device or simulator.

For more information about the reported issue, please check Apple's Developer Forum can be found [here](https://developer.apple.com/forums/thread/696804).

Before iOS 15.2 version there were no known issues when calling `PHPhotoLibrary.shared().register(self)` without authorization.

On devices running on iOS 15.2 you will get an error.

```
[GatekeeperXPC] Failed to open photo library Error Domain=com.apple.photos.error Code=41011 "Unauthorized access: client does not have valid TCC authorization" UserInfo={NSLocalizedDescription=Unauthorized access: client does not have valid TCC authorization}
```

The user needs to grant permission, and only then you shall call `PHPhotoLibrary.shared().register(self)`.

In the following video I verify this issue and the solution proposed.

%[https://youtu.be/ELGnrqbSyY8]
