首页 文章

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

提问于
浏览
0

我正在使用 Geofencing 作为我的一个申请 . 但我有一个问题 . 当应用程序处于 Background 模式时,我的应用程序未被调用 **- (void)locationManager:(CLLocationManager )manager didDetermineState:(CLRegionState)state forRegion:(CLRegion )region .

我在设置中检查 Background app refresh 标志是 ON .

以下是我的代码:

- (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

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

相关问题