简体   繁体   English

为什么定位服务不能用作后台任务?

[英]Why is location services not working as background task?

In my app there is a location (area) to be watched. 在我的应用程序中,有一个需要监视的位置(区域)。 When the device is moved away from that location (it could be a distance as small as 5 - 10 meters) an AlertView pops up and a sound is played. 将设备从该位置移开时(可能只有5-10米),会弹出AlertView并播放声音。 When the app is in the background an local notification is generated. 当应用程序在后台运行时,将生成本地通知。 Tapping or sliding the notification brings the app to the front. 点击或滑动通知会将应用程序置于最前面。 This works fine. 这很好。 However, when running in the background the location updates stoppes after 15-16 minutes or so. 但是,在后台运行时,该位置会在15-16分钟左右后更新Stoppes。 The arrow is removed from the status bar. 箭头从状态栏中删除。 Bringing the app to the front the AlertView pops up and the sound is played. 将应用程序置于最前面,AlertView会弹出并播放声音。 As far as I can see is location services getting a new fix on the current position and is the AlertView shown because the initial distance is greater then the area to be watched. 据我所知,位置服务正在对当前位置进行新的修复,是否显示了AlertView,因为初始距离大于要观察的区域。 Due to the small areas to be watched I think I could not use "significant-changes" or "didExitRegion". 由于要观察的区域很小,我认为我不能使用“重大更改”或“ didExitRegion”。 Is that true? 真的吗?

I set the tag in the info.plist to "App registers for location updates" in "required background modes". 我在“必需的后台模式”中将info.plist中的标记设置为“用于位置更新的应用程序注册”。

Is there anyone out there who has a clou about what's goiing on? 外面有人对发生的事情有疑虑吗? Do I have to put some code in - (void)applicationDidEnterBackground:(UIApplication *)application {} and if so.... what should that be? 我是否必须在-(void)applicationDidEnterBackground:(UIApplication *)application {}中放入一些代码,如果是的话...那应该是什么?

Thanks in advance, 提前致谢,

Regards, 问候,

Adri 阿德里

在startUpdatingLocation之前,您可以为所需的精度设置CLLocationManager的requiredAccuracy和distanceFilter字段

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

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