简体   繁体   English

iOS 7-后台位置应用在获取后台位置时被杀死

[英]iOS 7 - Background Location app getting killed when getting a background location

I have checked previous stackoverflow regarding this issue and have not gotten a proper answer. 我已经检查了有关此问题的以前的stackoverflow,但没有得到正确的答案。 I have CLLocationManager setup with region monitoring and getting location updates in the background. 我使用CLLocationManager设置了区域监视功能,并在后台获取位置更新。 I have enable the capabilities of the app to be Backgroud location update.. However I see that when I get the location update I get killed when I do some processing.. ie get the location and send it over to a server.. Any ideas why this is happening.. I have added log messages for all app delegates and I don't see any of them being fired either.. Any pointers will be appreciated.. 我已经启用了应用程序的功能,可以进行Backgroud位置更新。。但是,我看到当我获取位置更新时,我在进行一些处理时就被杀死了。例如,获取位置并将其发送到服务器。为什么会发生这种情况。我已经为所有应用程序代理添加了日志消息,但我也看不到它们被解雇了。任何指针都将不胜感激。

For #1 below are you suggesting: 对于以下#1,您建议:

- (void) _processNewLocationFromManager:manager

{
    // Process
}
- (void)locationManagerUpdatedLocation:(CSLocationManager *)manager
{
    BOOL isBackground = [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
    if (!isBackground || (isBackground && self.bgTask == UIBackgroundTaskInvalid)) {
        if (isBackground ) {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                [self beginBackgroundUpdateTask];
                [self _processNewLocationFromManager:manager];
                [self endBackgroundUpdateTask];
            });
        } else {
            [self _processNewLocationFromManager:manager];
        }
    }
}

- (void) beginBackgroundUpdateTask
{
    self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [self endBackgroundUpdateTask];
    }];
}

- (void) endBackgroundUpdateTask
{
    [[UIApplication sharedApplication] endBackgroundTask: self.bgTask];
    self.bgTask = UIBackgroundTaskInvalid;
}

1) Its supposed to redundant and not needed when you use background location, however I've found if you're not getting the execution behaviour you expect when using location then throwing in a beginBackgroundTaskWithExpirationHandler when updateLocations: gets called can sometimes fix issues like this. 1)它应该是多余的,在您使用后台位置时不需要,但是我发现如果您没有获得使用位置时所期望的执行行为,然后在updateLocations:被调用时抛出beginBackgroundTaskWithExpirationHandler有时可以解决这样的问题。

2) Another thing that you could try is setting pausesLocationUpdatesAutomatically to NO to see if it fixes things for you, but if it does it could use the batteries some more. 2)您可以尝试的另一件事是将pausesLocationUpdatesAutomatically自动设置为“否”,以查看它是否可以为您解决问题,但如果这样做可以使用更多电池。

3) Also another thing to try is if you have other background modes set at the same time as location (in particular backgroundFetch and remoteNotifications) you could try toggling them off temporarily to see if its having an adverse affect. 3)另一个尝试是,如果您同时在位置上设置了其他背景模式(尤其是backgroundFetch和remoteNotifications),则可以尝试暂时将其关闭,以查看其是否有不利影响。

4) One final thing, see if there are any other location based apps installed on your phone which are currently running, in my experience I've found if there's more than one location app running and they have different location manager setting set then one app can affect the behaviour of the other. 4)最后一件事,看看您的手机上当前是否正在运行其他基于位置的应用程序,以我的经验,我发现是否有多个位置应用程序正在运行,并且它们设置的位置管理器设置与一个应用程序不同会影响对方的行为。

None of these should have any affect on your program and they might not. 这些都不会对您的程序产生任何影响,也可能不会。 And people reading this might think these suggestions are crazy and just should not work.However I've been developing a couple of different location apps in parallel for the past few months and after many many many many debug sessions, logging sessions, observing location app behaviour when running in the background, I've come to the definite conclusion and am 100% convinced that all is not as it seems and is supposed to be (nor as is documented, nor is as it should be according to accumulated group wisdom and stack overflow answers) when it comes to location behaviour. 读过这篇文章的人可能会认为这些建议太疯狂了,应该行不通。但是,在过去的几个月中,在我进行了许多并行的调试工作,日志记录会话,观察位置应用之后,我一直在并行开发几个不同的位置应用在后台运行时的行为,我得出了明确的结论,并且100%确信一切都不是看起来和应该的(也没有记录,也没有根据积累的团体智慧和关于位置行为的问题。

There's something mysterious and screwy going on in location land sometimes. 有时,位置土地上发生了一些神秘而棘手的事情。

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

相关问题 获取iOS应用在后台甚至被杀的位置 - Getting location for an iOS app when it is in the background and even killed 当应用程序在后台时获取用户位置。 IOS - Getting user location when app is in background. IOS 是他们的任何cordova插件,即使android / ios应用被杀死,该插件也可提供后台服务以获取设备位置 - Is their any cordova plugin which provides background service for getting device location even if android/ios app is killed 仅在应用程序处于后台时才获取位置更新 - Getting Location Update only when app is in Background 当应用程序被杀死/终止/挂起时,cordova获取iOS 7和8的位置更新 - cordova getting Location Updates for iOS 7 and 8 when the App is Killed/Terminated/Suspended iOS 应用程序在后台被杀死 - 如何调试? - iOS app getting killed in background - how to debug? iOS:仅在开车时在后台获取位置更新 - iOS: Getting location updates in background only when in a car 在iOS 6/7的后台线程中获取用户的当前位置 - Getting users' current location in background thread for iOS 6/7 应用程序位置在iOS 8的后台 - App location in background on iOS 8 即使应用在iOS中被杀死或从后台删除,我如何继续更新我的位置? - How Can I Continue updating my location even when app is killed or removed from background in ios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM