当app在Background中时,CLLocationManager didDetermineState方法未被调用

时间:2016-09-19 08:22:40

标签: iphone cllocationmanager cllocation geofencing clregion

我正在使用 Geofencing 作为我的某个应用程序。但我有一个问题。当应用程序处于后台模式时,我的应用程序不会被称为 - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)stateRegion:(CLRegion *)region

我在设置中检查后台应用刷新标志是开启

以下是我的代码:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
    if (state == CLRegionStateInside)
    {
            NSLog(@"is in target region");
            UILocalNotification *notification = [[UILocalNotification alloc] init];
            notification.alertBody =  @"You are IN of REGION";
            notification.fireDate = [NSDate date];
            NSTimeZone* timezone = [NSTimeZone defaultTimeZone];
            notification.timeZone = timezone;
            notification.alertAction = @"Show";
            notification.soundName = UILocalNotificationDefaultSoundName;
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    }
    else
    {
           NSLog(@"is out of target region");
           UILocalNotification *notification = [[UILocalNotification alloc] init];
            notification.alertBody = @"You are OUT of REGION";
            notification.fireDate = [NSDate date];
            NSTimeZone* timezone = [NSTimeZone defaultTimeZone];
            notification.timeZone = timezone;
            notification.alertAction = @"Show";
            notification.soundName = UILocalNotificationDefaultSoundName;
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  }
}

CLLocationManager 已正确设置。我研究它,但没有得到适当的解决我的问题。任何人都可以帮助我吗?

由于

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。这是因为我在backgournd中标记了位置更新。 Here is image.