简体   繁体   English

在后台模式下接收GPS位置更新iOS 8

[英]receive gps location update in background mode ??iOS 8

i have used the following code when the app enters background but the location is not getting updated 当应用进入后台但位置未更新时,我使用了以下代码

if(noTripRunning && somethingLeftToSync){
    NSLog(@"Bg task started.");
    self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
        self.bgTask = UIBackgroundTaskInvalid;
        DebugLog(@"Background task complete.");
    }];
}
else if(self.bgTask != UIBackgroundTaskInvalid){
    [[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
    self.bgTask = UIBackgroundTaskInvalid;
    DebugLog(@"Ended background task.");
}

First of all, you should include some more information about your situation, for example the location code of the core location manager. 首先,您应该包括有关您的情况的更多信息,例如核心位置管理器的位置代码。 iOS 8 adds some new steps in order for the app to be able to start the process of asking for location updates. iOS 8添加了一些新步骤,以便该应用程序能够开始请求位置更新的过程。 If these steps are are not implemented correctly, the code will fail silently and you won't be notified why. 如果未正确执行这些步骤,则代码将静默失败,并且不会通知您原因。 more on this matter you should check out this link . 有关此事的更多信息,请查看此链接

Now to your question, I can't really give you a direct answer since you haven't provided enough information. 现在,对于您的问题,由于您没有提供足够的信息,我无法真正给您直接的答复。 But in any case, here is a very good example of how to work with updating the app's location in the background and keeping it from terminating. 但无论如何,这是一个很好的示例 ,说明了如何在后台更新应用的位置并防止其终止。 I would suggest to download the zip file and test it your self. 我建议下载zip文件并进行自我测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM