检查照片库的授权状态



是否有一种方法可以在新的iOS 6授权方案下检查应用程序的授权级别对设备的照片库?

换句话说,是否有相当于AbaddressbookgetAuthorizationstatus与照片库相反的等效物?

ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

ALAuthorizationStatus的文档显示可能的值。此API仅在iOS 6.0或更高版本下工作。

我正在使用此概念:

[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.
    }];

对于swift中的 PHPhotoLibrary,您应该得到 PHAuthorizationStatus的值:

    let authorizationStatus = PHPhotoLibrary.authorizationStatus()

返回值是:

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.
}

最新更新