在应用启动期间请求访问照片库 [英] Request access to photo library during app launch

查看:112
本文介绍了在应用启动期间请求访问照片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款能够在某些活动中自动拍照并将其直接保存到照片库的应用。不幸的是,用户在运行时可能并不总是看着他们的手机,并且第一次拍照时它要求获得访问照片的许可。

I'm working on an app that takes pictures automatically during certain events and saves them directly to the photo library. Unfortunately the user might not always be looking at their phone when this is running and the first time a picture is taken it asks for permission to access photos.

有没有办法可以在启动过程中强制执行此请求并将其排除在外?
谢谢

Is there a way I can force this request during launch and get it out of the way? Thanks

推荐答案

是的。您需要请求访问该库。

只需在AppDelegate中使用此代码 didFinishLaunchingWithOptions

Yes. You need to request access to the library.
Simply use this code in AppDelegate's didFinishLaunchingWithOptions

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];

这篇关于在应用启动期间请求访问照片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆