延迟位置更新iOS的问题 [英] Issue with deferred location updates ios

查看:80
本文介绍了延迟位置更新iOS的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去两天,我一直在尝试在应用程序中实施延迟的位置更新.我面临的问题是

 -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 

甚至在我调用

之后,每秒都会调用一次

方法

  [self.locMgr allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)200超时:(NSTimeInterval)25]; 

方法.

虽然我必须这么说

 -(void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)错误 

在我指定的25秒后恰好被调用 allowDeferredLocationUpdatesUntilTraveled 方法,错误代码= null.

据我的文档了解,didUpdateLocations仅应在25秒后调用.任何帮助将不胜感激.

解决方案

我一直在努力解决同一个问题,而且我可能已经找到了一个可以解决许多问题的答案-至少它可以解决我的问题并得到延期更新一直为我工作.我按照上面列表中的所有步骤进行操作,无论我做什么,都不会推迟位置更新.在我看来,我可能正在运行其他不允许系统进入睡眠状态的应用程序,因此我杀死了多任务托盘中的所有其他应用程序.我再次运行了示例应用程序,并且...奏效了!但是故事还不止于此.我稍后再试一次,即使在多任务托盘中没有其他应用程序在运行,我也无法推迟定位服务.然后我想到我的手机上有一个名为"Moves"的应用程序,即使您手动将其杀死,该应用程序仍可以保持其自身的生命.我不完全确定Moves在您杀死它后如何神奇地复活,但确实如此(也许使用蓝牙和应用程序保存/恢复服务).即使它处于活动状态并正在跟踪您的位置,它也不会出现在多任务处理托盘中.我认为只有手动启动的应用程序才会出现在任务栏中-如果操作系统启动了某个应用程序,则它不会出现在任务栏中.但是我离题了……通过禁止Moves使用位置服务,我能够使延迟的位置服务在我的应用程序中始终如一地工作.当我这样做时,即使它不在多任务处理托盘中,Moves也会抱怨.看来,如果另一个应用程序正在使用位置服务(而不是延迟),则您的应用程序也不会延迟.

I have been trying to implement deferred location updates in an app for the past two days. The problem I am facing is that

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

method is being called each second even after I call the

 [self.locMgr allowDeferredLocationUpdatesUntilTraveled:(CLLocationDistance)200 timeout:(NSTimeInterval)25];

method.

ALthough I have to say that

 - (void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error

is called exactly after 25 seconds as specified by me allowDeferredLocationUpdatesUntilTraveled method with error code = null.

It is my understanding from the docs that didUpdateLocations should be called after 25 seconds only. Any help would be much appreciated.

解决方案

I have been struggling with the same issue, and I may have found an answer that solves this problem for many - at least it solves my problem and gets deferred updates working consistently for me. I followed all of the steps in the list above and no matter what I did, location updates would not defer. It occurred to me that I might have other apps running that were not allowing the system to sleep, so I killed all other apps in the multitasking tray. I ran my sample app again and ... it worked! But the story doesn't end there. I tried again a little later, and even though there were no other apps running in the multitasking tray I couldn't get location services to defer. Then it occurred to me that I have an app on my phone called "Moves" which manages to keep itself alive even after you manually kill it. I'm not entirely sure how Moves comes magically back to life when you kill it, but it does (perhaps using bluetooth and the app preservation / restoration service). Even though it is alive and tracking your location it doesn't appear in the multitasking tray. I think that only apps that are manually launched appear in the tray - if the OS launches an app it doesn't appear in the tray. But I digress ... I was able to get deferred location services to work consistently in my app by disallowing Moves to use location services. When I did, Moves complained even though it wasn't in multitasking tray. It seems that if another app is using location services (and not deferring) your app won't defer either.

这篇关于延迟位置更新iOS的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆