ALAuth检查不起作用

时间:2015-10-16 00:31:17

标签: ios objective-c alassetslibrary

我正在尝试检查用户是否允许我的应用程序访问照片的权限(仅限Objective-C),但我收到以下错误:

Error 1: initializer element is not compile-time constant
Error 2: Excepted identifier or '('

以下是代码:

#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>

//(Error 1) ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

//(Error 2) if (status != ALAuthorizationStatusAuthorized) {
    //show alert for asking the user to give permission

}

这些代码在我的.m文件中,如何解决此问题(请包含代码)?

1 个答案:

答案 0 :(得分:0)

哎呀,我犯了一个小错误。我忘了添加viewdidload

#import <UIKit/UIKit.h>
#import "BaseViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>

@interface ViewController14 ()

@end

@implementation ViewController14
- (void)viewDidLoad
{
    [super viewDidLoad];
    ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];

    if (status != ALAuthorizationStatusAuthorized) {
        //show alert for asking the user to give permission

    }
}

@end