小编scu*_*oni的帖子

应用程序进入后台后每n分钟获取用户位置

我正在尝试实施这篇文章中给出的建议.

不幸的是,我不清楚这些步骤.我尝试实现这些建议,但是即使在我启动和停止locationServices之后,backgroundTimeRemaining仍然继续减少.这就是我开发它的方式:

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

    UIApplication*    app = [UIApplication sharedApplication];

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task.
        self.timer = nil;
        [self initTimer];

    });
}
Run Code Online (Sandbox Code Playgroud)

initTimer:

- (void)initTimer {

    // Create the location manager if this object does not
    // already have one.
    if (nil == self.locationManager)
        self.locationManager = [[CLLocationManager alloc] init];

    self.locationManager.delegate = self;
    [self.locationManager …
Run Code Online (Sandbox Code Playgroud)

iphone background objective-c locationmanager ios

27
推荐指数
2
解决办法
3万
查看次数

标签 统计

background ×1

ios ×1

iphone ×1

locationmanager ×1

objective-c ×1