Significant Location Update
当请求地理位置权限时,可以请求“后台定位”的权限,当有后台定位权限时,应用可以调用 CLLocationManager的startMonitoringSignificantLocationChanges方法启用“显著位置变化的监听”,当GPS位置有明显变化时(实际测试一般4、5百米),应用会在后台启动。
首先,需要CLLocationManager请求后台定位权限(Always)权限,
代码块
-[CLLocationManager requestAlwaysAuthorization]
当有了Always的权限,应用启动时就可以调用 startMonitoringSignificantLocationChanges 开始监听显著位置变化了。
代码块
-[CLLocationManager startMonitoringSignificantLocationChanges]
当调用后,下次地理位置发送显著变化,就会把应用从后台启动,并调用下面的方法:
代码块
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations{
}
本文介绍如何使用CLLocationManager在iOS应用中实现显著位置变化监听。通过请求后台定位权限并调用startMonitoringSignificantLocationChanges,应用可在GPS位置显著变化时从后台启动。

5695

被折叠的 条评论
为什么被折叠?



