gpt4 book ai didi

ios - 在 iOS 上持续跟踪用户位置

转载 作者:可可西里 更新时间:2023-11-01 04:02:13 24 4
gpt4 key购买 nike

我需要持续监控用户的位置,以便在他靠近有趣的东西时通知他。实现这一目标的正确方法是什么?

我无法让计时器在后台运行(以定期更新用户在服务器上的位置),我还了解到即使应用程序未运行,订阅重要的位置更改也能让我收到位置更新,但我无法让它发生。我在正确的道路上吗?还有其他选择吗?

编辑 -有一个我应该暴露的必要条件,这可能让我失去了对真正问题的关注:

  • 用户周围有趣的“东西”没有固定位置,因此在发送推送之前,我必须确保用户当前在该位置(当然我可以假设 n分钟)。

最佳答案

您可以在您的 VC 中设置监控位置,如下所示

在 viewDidLoad 方法中做如下操作

CLLocationManager locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;(Accuracy according to your need)
[locationManager startUpdatingLocation];

你必须重写下面两个可选的 CLLocationManagerDelegate 协议(protocol)委托(delegate)方法

适用于 iOS6+

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

适用于 iOS 2 到 6

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

在这些方法中,您将获得更新的位置。随心所欲地使用它。每次位置更新时,这些方法都会调用。

关于ios - 在 iOS 上持续跟踪用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21624522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com