当你第一次尝试访问用户的ALAssetsLibrary时,操作系统会向他们显示一个对话框,请求许可。如果它们不允许这样做,则将调用failureBlock,并且在将来将始终调用该and。有没有办法再次强制提示此授权请求?
我注意到,在地图应用程序中,它们会通知用户转到设置应用程序,用一个按钮打开定位服务。然而,据我所知,没有办法以编程方式打开设置应用程序。我应该只显示如何打开定位服务的指示吗?
发布于 2011-05-04 06:47:39
你不能以苹果批准的方式打开设置应用程序。最好的方法是捕获错误,然后显示一个UIAlertView或其他视图,其中包含如何执行此操作的说明。看看Dropbox应用程序的最新版本,了解它们是如何指导用户的。
发布于 2012-12-23 00:46:48
当您尝试从代码访问库时,可以使用错误处理程序来捕获错误,并向用户显示一个警告,指定要执行的操作。
示例
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];
}
}https://stackoverflow.com/questions/5876236
复制相似问题