iphone ios 如何检查提示用户关闭全部定位和程序定位服务

访问系统相册与定位服务权限管理
本文探讨了在程序访问系统相册时遇到的权限问题,特别是当用户关闭了定位服务时如何影响访问相册操作。文章提供了判断定位服务状态的方法,并在无法访问相册时提示用户开启定位服务。

关键字:ALAssetsLibraryErrorDomain  3312

 

    ALAssetsLibraryErrorDomain 3311

ALAssetsLibraryAccessUserDeniedError ALAssetsLibraryAccessGloballyDeniedError

 

当程序访问系统相册的图片,或使用定位服务的时候,如果用户关闭了全局定位服务,或者关闭了我们程序定位服务,那么我们程序访问相册将会失败。

比如使用 

- (void)enumerateGroupsWithTypes:(ALAssetsGroupType)types usingBlock:(ALAssetsLibraryGroupsEnumerationResultsBlock)enumerationBlock failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock;

访问相册,会在failureBlock中返回error。

可以使用以下代码来确认是否能访问。

注意

authorizationStatus 这个函数需要os4。2

 

 

if ([CLLocationManager locationServicesEnabled] &&
			[CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized )
{
   //Do ALAssetLibrary work here...
}
else
{
 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
 NSLocalizedString( @"Please Enable Location Service's", @"Please Enable Location Service's" )
                 message: NSLocalizedString( @"Message", @"Message" )
                 delegate: self
   cancelButtonTitle: NSLocalizedString( @"Close", @"Close" )
   otherButtonTitles: nil];
 
			[alert show];
}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值