【问题标题】:ALAssetsLibrary ALAssetsLibraryAccessUserDeniedErrorALAssetsLibrary ALAssetsLibraryAccessUserDeniedError
【发布时间】:2011-08-18 02:06:51
【问题描述】:

当您第一次尝试访问用户的 ALAssetsLibrary 时,操作系统会向他们显示一个对话框,要求他们获得许可。如果他们不允许这样做,一个 failureBlock 将被调用,并且在未来总是会被调用。有没有办法强制再次提示这个授权请求?

我注意到在地图应用程序中,他们通知用户转到设置应用程序以使用按钮打开位置服务。但是,我不知道以编程方式打开“设置”应用程序。我应该只显示有关如何打开位置服务的说明吗?

【问题讨论】:

    标签: iphone ios cgimage alasset assetslibrary


    【解决方案1】:

    您无法以 Apple 批准的方式打开设置应用程序。 您可以期望的最好的方法是捕获错误,然后显示 UIAlertView 或其他视图,其中包含有关如何执行此操作的说明。查看 Dropbox 应用程序的最新版本,了解它们如何指导用户。

    【讨论】:

    • 有没有办法在不启用定位服务的情况下从资源库中获取图片?
    • 可以发出警报并引导用户直接进入设置应用程序的“定位服务”部分。在此处查找已知的 url 方案:stackoverflow.com/questions/8246070/…
    【解决方案2】:

    当您尝试从您的代码访问库时,您可以使用错误处理程序来捕获错误并向用户显示指定操作的警报。

    示例

    failureBlock:^(NSError *error) {
        // error handling
        if (error.code == ALAssetsLibraryAccessGloballyDeniedError) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
                message:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services'." 
                delegate:self cancelButtonTitle:@"OK" 
                otherButtonTitles:nil, nil];
            [alert show];
        } else if (error.code == ALAssetsLibraryAccessUserDeniedError) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
                message:[NSString stringWithFormat:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services' for %@.", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]] 
                delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        } else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Error loading image..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
            [alert show];
        }
    }
    

    【讨论】:

    • 你叫什么方法?
    • 你的代码只显示了一部分,你的意思是使用enumerateGroupsWithTypes方法吗?
    • @jianpx 这样的东西ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library assetForURL:referenceURL resultBlock:^(ALAsset *asset)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多