重要的位置变化监控在后台

时间:2016-03-28 05:42:36

标签: ios objective-c iphone cocoa-touch cllocationmanager

我有一个应用程序,用于检查用户是否接近我的客户的某个商店,当他这样做时,应用程序会向他发送通知,告诉他他在商店附近。

当然我正在使用地理围栏(locationManager: didEnterRegion),我在locationManager: didUpdateLocations上有20多家商店,我正在为用户分类最近的20家商店。

我正在CLLocationManager上以AppDelegate方式配置ViewController,然后将locationManager locationManager属性设置为对象(因为我想使用相同的AppDelegate 1 {}也在-(void)configureLocationManager { //Initializing "locationManager"'s(CLLocationManager) self.locationManager=[[CLLocationManager alloc] init]; //Setting "locationManager"'s(CLLocationManager)'s delegate to "monitorLocationVC"(monitorLocationViewController) self.locationManager.delegate=self.monitorLocationVC; //Setting "locationManager"'s(CLLocationManager)'s distance filter to 10 self.locationManager.distanceFilter=10; //Setting "locationManager"'s(CLLocationManager)'s activityType to navigation self.locationManager.activityType=CLActivityTypeAutomotiveNavigation; //setting "locationManager"'s(CLLocationManager) desiredAccuracy to "best" self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; //Setting "locationManager"'s(CLLocationManager)'s pausesLocationUpdatesAutomatically to NO self.locationManager.pausesLocationUpdatesAutomatically=NO; //If OS version is 9 or above - setting "allowsBackgroundLocationUpdates" to YES if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) { self.locationManager.allowsBackgroundLocationUpdates = YES; } } 上:

Xamarin Studio

到目前为止一切正常,但现在我看到应用程序开始运行几分钟后才开始在后台通知商店(通知大约15分钟,然后突然停止)。

注意:有时当我从主屏幕启动我的应用程序(只是正常启动)应用程序崩溃时,这可能是问题吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

查看此文档并添加后台获取模式:documentation apple

并添加此代码:

if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
    [self.locationManager requestAlwaysAuthorization];
}
if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
    [self.locationManager setAllowsBackgroundLocationUpdates:YES];
}