Jacob Joz
Jacob Joz

Reputation: 732

Detecting ALAuthorizationStatus change iOS

I'm having an issue where I need to check if the app has access to photos. It prompts the user to decide through the standard privacy pop up. However, it looks like the app doesn't wait for the user to decide and continues on (in no permission mode). So even if the user allows it, it still shows my custom permissions required message box.

//force the privacy prompt
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib assetForURL:[NSURL URLWithString:@""] resultBlock:nil failureBlock:nil];

//then check for permission
ALAuthorizationStatus authStatus = [ALAssetsLibrary authorizationStatus];

//1.
if(authStatus != ALAuthorizationStatusAuthorized)
{
  //show custom permissions required message box
}

Is there some way to get notified regarding the change in permissions and move my code at 1. to that method instead?

Thanks

Jacob

Upvotes: 2

Views: 1746

Answers (1)

skg
skg

Reputation: 141

I found out after some testing that applicationDidBecomeActive gets called after the photo permissions alert view is dismissed.

I used NSNotificationCenter and was able to capture the authorizationStatus change event. This is untested below iOS 7.

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidBecomeActive:)
                                                 name:UIApplicationDidBecomeActiveNotification
                                               object:nil];

Upvotes: 5

Related Questions