Christopher King
Christopher King

Reputation: 1715

check for authorization status to photo library

Is there a way to check for your app's authorization-level to the device's photo library under the new iOS 6 authorization scheme?

In other words, is there an equivalent for ABAddressBookGetAuthorizationStatus that goes against the photo library instead?

Upvotes: 2

Views: 4196

Answers (3)

Christian Navelot
Christian Navelot

Reputation: 1164

For the PHPhotoLibrary in Swift, you should get the value of PHAuthorizationStatus :

    let authorizationStatus = PHPhotoLibrary.authorizationStatus()

Return values are :

public enum PHAuthorizationStatus : Int {  

    case notDetermined // User has not yet made a choice with regards to this application

    case restricted // This application is not authorized to access photo data.

// The user cannot change this application’s status, possibly due to active restrictions
//   such as parental controls being in place.
    case denied // User has explicitly denied this application access to photos data.

    case authorized // User has authorized this application to access photos data.
}

Upvotes: 1

rmaddy
rmaddy

Reputation: 318914

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

The docs for ALAuthorizationStatus show the possible values. This API only works under iOS 6.0 or later.

Upvotes: 6

NeverBe
NeverBe

Reputation: 5038

I am using this contruction:

[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
        if (*stop) {
            return ;
        }
// TODO : access granted
    *stop = TRUE;
    } failureBlock:^(NSError *error) {
        // TODO: User denied access. Tell them we can't do anything.
    }];

Upvotes: 1

Related Questions