iOS 10 now requires the user's permission to access the Media Library. We check if we have access to the Media Library before we use it, and if not we then use [MPMediaLibrary requestAuthorization:
to request authorization again from the user.
I'm expecting this to show the same popup request to access the Media Library that we get at app startup, but nothing happens. It is simply returning with the MPMediaLibraryAuthorizationStatusDenied
status from before.
The docs for requestAuthorization are incomplete at this time, so I can't tell if I'm just using this incorrectly, or there is something else wrong.
if ( MPMediaLibrary.authorizationStatus == MPMediaLibraryAuthorizationStatusAuthorized)
{
// we already have access to the Media Library - use it here...
}
else
{
// We expect this to show a popup so the user can grant access, but does not work
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus authorizationStatus)
{
if ( authorizationStatus == MPMediaLibraryAuthorizationStatusAuthorized )
{
// success: the user authorized - use it here...
}
else
{
// user did not authorize - tell user why here...
}
}];
}
Update
Apparently there is no way to cause the original dialog to reappear (see comments below). I'm now using this code to at least take me to the right place in settings so the user can make the change. (for iOS8 and beyond)
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
The MPMediaLibrary will only automatically prompt the user once. The state is
MPMediaLibraryAuthorizationStatusNotDetermined
if you ask for it before it has been granted or denied by the user. If they have denied access previously, you need to send the user to the System Settings so they can manually turn it on for your app.The following code is how we are doing it.