[英]GPS app stopped working on iOS 5 - Location Manager not updating
我开发了一个针对iOS 4.3的应用程序。 它工作正常。 但是自从我迁移到iOS 5.0后,该应用程序开始出现奇怪的行为。 位置管理员未显示位置变化的更新。 有谁遇到过这种问题?
谢谢你的帮助。
从iOS 4.x迁移到5时,我与CLLocation经理分享了奇怪的更新问题:
您是否已将CLLocationManager对象子类化?
问题 :在某些情况下,某些时候委托方法有时不会被调用(例如didUpdateLocation)。
修复 :不要子类化CLLocationManager
希望这可以帮助 :)
iOS 5处理内存管理的方式可能是一种方式。 如果您在.h文件中声明变量而没有正确或隐式地引用它[self.myVar doSomething]; 如果你不知道它,它可能会倾倒在你身上。 它仍然可以正常编译,但主要会被忽略并传递。
不是100%没有看到代码,但我已经注意到这个问题以及我们公司的一些旧程序,当iOS 5来电时。 祝好运。
核心位置框架中包含的关键类是CLLocationManager和CLLocation。 在应用程序中创建CLLocationManager类的实例,并设置属性以指示应用程序所需的位置准确性级别。 然后指示位置管理员开始跟踪位置信息:
CLLocationManager *locationMgr =
[[CLLocationManager alloc] init];
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
locationMgr.delegate = self;
[locationMgr startUpdatingLocation];
每次更新位置时,位置管理器都会调用名为didUpdateToLocation的应用程序委托方法,并传递有关当前位置的信息。 因此,上面的代码也将当前类指定为位置管理器的委托。
如果您感兴趣我从这里得到这些信息,它是专门为iOS 5制作的: http : //www.techotopia.com/index.php/Getting_iPhone_Location_Information_using_the_iOS_5_Core_Location_Framework
在缓存位置的应用程序中遇到间歇性问题。 有时,位置服务需要比预期更长的时间来返回位置,而是返回最后一个缓存位置。 请参阅此iOS文档示例, 该示例使用howRecent
变量来过滤掉可能已缓存的位置。
为了防止Apple更改其URL,此处列出了相关的委托方法:
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// If it's a relatively recent event, turn off updates to save power
NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0)
{
NSLog(@"latitude %+.6f, longitude %+.6f\n",
newLocation.coordinate.latitude,
newLocation.coordinate.longitude);
}
// else skip the event and process the next one.
}
这有效地忽略了超过15秒的任何位置。 我们在我们的应用中将间隔设置为5.0
,但您必须进行试验以了解哪种方法适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.