【问题标题】:Track iOS Device Motion Updates in Background for more than 10 minutes在后台跟踪 iOS 设备运动更新超过 10 分钟
【发布时间】:2016-05-17 07:27:18
【问题描述】:

我有一个应用程序,它在后台每秒检查一次 iPhone 的重力。当我在连接到 Xcode 时运行此代码时,程序在后台运行了 30 多分钟。但是,当它没有连接到 Xcode 时,它​​会在后台运行 10 分钟前停止运行。我使用位置更新和动作更新:

- (void)applicationDidEnterBackground:(UIApplication *)application {

    bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        bgTask = UIBackgroundTaskInvalid;
        NSLog(@"End Background Tasks");
    }];

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
        [locationManager requestAlwaysAuthorization];
    }
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9) {
        locationManager.allowsBackgroundLocationUpdates = YES;
    }
    [locationManager startUpdatingLocation];

    [self.motionManager startDeviceMotionUpdates];
}

【问题讨论】:

标签: ios cllocationmanager background-task devicemotion


【解决方案1】:

检查目标是否在功能下启用了后台模式,并确保设置了位置更新模式。

【讨论】:

  • 我这样做了,两者都设置好了。
猜你喜欢
  • 2013-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多