GPS 应用程序在 iOS 5 上停止工作 - 位置管理器未更新

发布于 2024-12-11 07:56:55 字数 115 浏览 0 评论 0原文

我开发了一个针对 iOS 4.3 的应用程序。效果很好。但自从我迁移到 iOS 5.0 以来,该应用程序开始表现出奇怪的行为。位置管理器不显示位置变化的更新。有人遇到过这种问题吗?

感谢您的任何帮助。

I have developed an app targeted for iOS 4.3. It worked fine. But since I migrated to iOS 5.0, the app has started showing strange behavior. The location manager is not showing updates on change in position. Has anyone encountered this kind of problem?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

如何视而不见 2024-12-18 07:56:55

我与 CLLocation 经理共享票价,出现奇怪的更新问题
从 iOS 4.x 迁移到 5 时:

  1. 您是否对 CLLocationManager 对象进行了子类化?

    • 问题
      在这种情况下,有时委托方法有时
      不要被呼叫(例如 didUpdateLocation)。

    • 修复:不要子类化 CLLocationManager

  2. CLLocationManager 是从 Singleton 实例化的吗?
    • 问题:使用 CLLocationManager 对象作为属性
      单例对象在 4.x 中工作正常,但在 iOS5 中不一致
    • 修复:将对象移至非单例对象
  3. 如果上述任一方法有帮助,或者您尝试过但失败
    • 问题:由于某种原因,CLLocationManager 仍然无法运行
      来自主线程,因此您会遇到奇怪的行为。
    • fix#1:创建 CLLocationManager 对象作为 appDelegate 中的属性
      无需子类化它。 (事实证明,即使在越狱的 iPhone 上,该解决方案也效果最佳
      。如果您的设计与情况 2 类似,您仍然可以使用从单例指向其实例的动态属性。
    • fix#2:一个更肮脏的解决方案是确保它使用 performSelectorOnMainThread 或其他方式从主运行循环运行

希望这有帮助:)

I had my fare share with CLLocation manager weird updating issues
when moving from iOS 4.x to 5:

  1. Have you subclassed the CLLocationManager object ?

    • problem :
      In that case sometime the delegate methods sometime
      don't get called (ex. didUpdateLocation).

    • fix: don't subclass CLLocationManager

  2. Is the CLLocationManager instanced from a Singleton ?
    • problem: using the CLLocationManager object as a property
      of a singleton object worked fine in 4.x but was inconsistent in iOS5
    • fix:move the object to a non-singleton object
  3. If either of the above helps , or you've tried it and it failed
    • problem: for some reason the CLLocationManager still doesn't run
      from the main thread and so you experience the strange behavior.
    • fix#1: create the CLLocationManager object as a property in the appDelegate
      without subclassing it . (this solution proved to work best , even on jailbroken iphones)
      . you can still use a dynamic property pointing to it's instance from the singleton if you design is similar to case 2.
    • fix#2: a more dirty solution is making sure it runs from the main runloop either using performSelectorOnMainThread or some other way

Hope this helps :)

蹲在坟头点根烟 2024-12-18 07:56:55

iOS 5 处理内存管理的方式可能是一种方式。如果您在 .h 文件中声明变量并且没有正确或隐式引用它 [self.myVar doSomething];它可能会在你不知情的情况下倾倒在你身上。它仍然可以正常编译,但主要会被忽略和忽略。

没有看到代码就不是 100%,但当 iOS 5 到来时,我也注意到了我们公司的一些旧程序的这个问题。祝你好运。

The way iOS 5 handles memory management could be one way. If you are declaring a variable in your .h file and not referencing it correctly or implicitly [self.myVar doSomething]; it could be dumping out on you without you knowing it. It will still compile fine, but will mainly be ignored and passed over.

Not 100% without seeing code, but I have noticed this issue as well with some of our company's older programs when iOS 5 came calling. Good luck.

逆流 2024-12-18 07:56:55

核心位置框架中包含的关键类是
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

The key classes contained within the Core Location framework are
CLLocationManager and CLLocation. An instance of the CLLocationManager
class is created within the application and a property set to indicate
the level of location accuracy that is required by the application.
The location manager is then instructed to start tracking location
information:

CLLocationManager *locationMgr = 
      [[CLLocationManager alloc] init];
locationMgr.desiredAccuracy = kCLLocationAccuracyBest;
locationMgr.delegate = self;

[locationMgr startUpdatingLocation];

With each location update, an application delegate method named
didUpdateToLocation is called by the location manager and passed
information about the current location. The above code also,
therefore, assigns the current class as the location manager’s
delegate.

Also in case you were interested I got this information from here and it is made specifically for iOS 5: http://www.techotopia.com/index.php/Getting_iPhone_Location_Information_using_the_iOS_5_Core_Location_Framework

想挽留 2024-12-18 07:56:55

在缓存位置的应用程序中遇到间歇性问题。有时,位置服务返回位置的时间比预期要长,而是返回最后缓存的位置。请参阅 这个 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,但您必须进行试验才能知道哪种方法最适合您。

Ran into an intermittent problem in an app where the location was cached. Sometimes location services takes longer than expected to return a location, and instead it returns the last cached location. See this iOS documentation example that uses a howRecent variable to filter out locations that are likely cached.

Just in case Apple changes their URL, the relevant delegate method is listed here:

// 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.
}

This effectively ignores any locations older than 15 seconds. We set the interval to 5.0 in our app, but you'll have to experiment to see what works well for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文