暂停后iPhone背景中的iPhone GPS永远不会恢复 [英] iPhone GPS in background never resumes after pause

查看:139
本文介绍了暂停后iPhone背景中的iPhone GPS永远不会恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要在后台跟踪用户位置更改,并且只要用户四处移动就可以正常工作。
当用户停止并且 CLLocationManager 在10-20分钟左右后暂停。此通知表明:

My application needs to track user location changes in the background and works fine as long as user moves around. When user stops and CLLocationManager pauses after 10-20 minutes or so. It is indicated by this notification:

-(void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager{}

这对我也没关系。好的,我节省了一些电池等。

And this is also fine with me. Great, I save some battery, etc.

问题是当用户再次开始移动时, CLLocationManager 永远不会醒来并且在我将应用程序置于前台之后,委托方法永远不会被触发(变为活动状态):

The problem is that CLLocationManager never wakes up when user starts moving again and following delegate methods are never fired until I put my application to the foreground (gets active):

//Never called back after CLLocationManager pauses:
-(void)locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager{}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{}

为什么 locationManagerDidResumeLocationUpdates never设备开始再次移动后调用? GPS也不应该自动恢复(因为自动暂停)?
有没有办法在没有用户互动的情况下恢复GPS?

Why is locationManagerDidResumeLocationUpdates never called after device starts moving again? Shouldn't GPS resume automatically also (since was paused automatically)? Is there a way to resume GPS without user's interaction?

应用程序已经以下在Info.plist文件中声明:

Application has following declared in Info.plist file:

我的CLLocationManager设置是:

And my CLLocationManager settings are:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setActivityType:CLActivityTypeFitness];
//I WANT pauses to save some battery, etc... That is why following line is commented out (default)
 //[locationManager setPausesLocationUpdatesAutomatically:NO];
 locationManager.distanceFilter = kCLLocationAccuracyNearestTenMeters;
 locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
 [locationManager startUpdatingLocation];


推荐答案

如果您搜索 pausesLocationUpdatesAutomatically 在Apple论坛上你会发现一个类似行的最近一个问题,得到了Apple开发者的回复。我不会直接在这里重新发布它,因为它是一个私人论坛,但要点是,当用户忘记他们已经有位置感知应用正在运行并且已停止使用时,位置暂停是用于实例的它。通过暂停更新,他们的电池不会快速耗尽。不幸的是,不可能知道新的移动是他们恢复活动还是做其他事情,所以在应用程序回到前台之前不会恢复更新。他们的建议是捕获暂停调用并以某种方式引起用户的注意,以便他们在需要更新时打开应用程序。

If you search for pausesLocationUpdatesAutomatically on the Apple forums you'll find a recent question along similar lines which has had a response from an Apple developer. I won't repost it directly here since it is a private forum, but the gist is that the location pausing is for instances when the user forgets that they have got a location aware app running and have stopped using it. By pausing updates their battery won't be drained as quickly. Unfortunately it's not possible to know whether new movement is them resuming the activity or doing something else, so updates don't resume until the app comes back to the foreground. Their suggestion is to catch the pause call and get the user's attention somehow to get them to open the app if they still want updates.

编辑:

来自Apple自己的 pausesLocationUpdatesAutomatically 。他们建议:

From Apple's own documentation of pausesLocationUpdatesAutomatically. They suggest:


暂停发生后, 负责在您确定时再次重新启动位置服务他们是需要的。核心位置调用 locationManagerDidPauseLocationUpdates(_:)
您的位置经理代表的方法,让您知道已经发生
暂停。在该方法中,您可以配置本地
通知,其触发器的类型为 UNLocationNotificationTrigger
并设置为在用户退出当前区域时通知。本地通知的
消息应该提示用户再次启动
您的应用,以便它可以恢复更新。

After a pause occurs, it is your responsibility to restart location services again when you determine that they are needed. Core Location calls the locationManagerDidPauseLocationUpdates(_:) method of your location manager's delegate to let you know that a pause has occurred. In that method, you might configure a local notification whose trigger is of type UNLocationNotificationTrigger and is set to notify when the user exits the current region. The message for the local notification should prompt the user to launch your app again so that it can resume updates.

这篇关于暂停后iPhone背景中的iPhone GPS永远不会恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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