如何在启动时要求访问照片库?

时间:2014-11-08 18:11:34

标签: xcode photo startup undeclared-identifier

我正在构建一个应用程序,让用户从他们的库中拍照来做事情。我使用的是X代码,而且我的代码是在&f; finishLaunchingWithOptions'但不断获得一个未声明的标识符'错误。怎么办?

ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator =
^(ALAssetsGroup *assetGroup, BOOL *stop) {
    if (assetGroup != nil) {
        // do somthing
     }
};

ALAssetsLibraryAccessFailureBlock assetFailureBlock = ^(NSError *error) {
    LogError(@"Error enumerating photos: %@",[error description]);

};

NSUInteger groupTypes = ALAssetsGroupAll;

[library enumerateGroupsWithTypes:groupTypes usingBlock:assetGroupEnumerator failureBlock:assetFailureBlock];

1 个答案:

答案 0 :(得分:0)

答案太迟了但你需要定义库

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

或更好地使用类方法,如果您要重用该库以进行更多查询

+ (ALAssetsLibrary *)defaultAssetsLibrary
{
    static dispatch_once_t pred = 0;
    static ALAssetsLibrary *library = nil;
    dispatch_once(&pred, ^{
        library = [[ALAssetsLibrary alloc] init];
    });
    return library;
}