1.使用期间定位”模式‘’
a、info.plist 配置NSLocationWhenInUseUsageDescription
b、调用方法requestWhenInUseAuthorization申请使用期间定位模式
有且只有status == kCLAuthorizationStatusNotDetermined的时候,调用才会出现系统弹窗。
注意:如果用户选择“允许一次”,则状态更改为kCLAuthorizationStatusAuthorizedWhenInUse,但是设置还是为"询问"状态,下次App启动的时候,还是status == kCLAuthorizationStatusNotDetermined需要进行授权弹窗。
2.“始终定位”模式
只有当你的App确实需要始终定位的时候,才配置。该模式下,AppStore的审核也会更加的严格。
a、info.plist 同时配置以下项目
NSLocationAlwaysAndWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription
需要支持 iOS10 的话需要配置NSLocationAlawaysUsageDescription
b、调用方法requestAlwaysAuthorization
该方法的调用时机非常重要,否则可能永远都出不来弹窗。
场景一、
当status == kCLAuthorizationStatusNotDetermined时,必须首先调用requestWhenInUseAuthorization,只有用户同意“应用内使用”的情况下才有用。
当status == kCLAuthorizationStatusAuthorizedWhenInUse时,调用requestAlwaysAuthorization出现始终授权模式弹窗。
场景二、试过好像没有达到条件,需要继续摸索。
当status == kCLAuthorizationStatusNotDetermined时,直接调用requestWhenInUseAuthorization,官方文档说会出现两次弹窗。第一次弹窗征求用户同意使用期间授权模式,同意后,如果App短时处于使用定位状态,将会出现二次弹窗。If the app is in the Provisional Always state, the system displays the second prompt with the string from NSLocationAlwaysUsageDescription.
网友评论