gpt4 book ai didi

iOS 在用户移动时收到通知

转载 作者:行者123 更新时间:2023-11-28 21:53:53 25 4
gpt4 key购买 nike

我一直在努力寻找一种从 BT 设备定期检索信息的方法。我的蓝牙设备通常位于车辆中,所以我的问题是是否可以使用说...(如果用户行驶 > 10 公里/小时)来运行任务。或者在重大地点变更时。

是否有可能得到一个真正的路线位置,我可以用它来大致了解用户是否在移动?我只需要它每隔几天触发一次(当用户开车时)。初始设置后,用户从未与我的应用交互。

谢谢。

cmyr建议的实现:

CLLocationManager *locationManager;
int badge_count = 0;
- (void)startSignificantChangeUpdates
{
// Create the location manager if this object does not
// already have one.
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;

locationManager.pausesLocationUpdatesAutomatically = YES;

locationManager.activityType = CLActivityTypeAutomotiveNavigation;

[locationManager requestAlwaysAuthorization];

locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
locationManager.distanceFilter = 500; // meters

[locationManager allowDeferredLocationUpdatesUntilTraveled:501 timeout:-1];
[locationManager startMonitoringSignificantLocationChanges];
[locationManager startUpdatingLocation];
}
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
badge_count++;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge_count];
NSLog(@"Location Event WOOT!");
}

不幸的是我无法触发事件。我已将位置更新添加到应用程序列表中。

上面的代码包含在我的 app delegate.m 文件中

最佳答案

Core Location 有一组专门针对此用例的 API,Apple 将其称为 Significant Location Change Monitoring .

来自文档:

The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.

此 API 仅在您行驶了指定距离时更新您的位置。它不提供持续更新。如果您需要不断更新,则必须使用标准定位服务。

关于iOS 在用户移动时收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277960/

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