我正在使用一个非常简单的基于GPS的应用程序,用户可以监控他们的驾驶。通常,这是用户驱动程序所做的事情:
我想要Apple Watch配套应用程序,我会找到这两个按钮。所以有两种情况:
A /当应用处于前景时,没有问题。
B /当应用程序处于后台或未启动时,我无法获得任何gps更新。什么都没发生。纳达。
这里有一些代码。
当用户按下"我驾驶"手表上的按钮和应用程序未在模拟器中启动:
// Regular location manager
self.standardLocationManager = [[CLLocationManager alloc] init];
self.standardLocationManager.delegate = self;
self.standardLocationManager.desiredAccuracy = self.accuracy;
self.standardLocationManager.activityType = CLActivityTypeAutomotiveNavigation;
self.standardLocationManager.distanceFilter = self.distanceFilter;
[self.standardLocationManager requestWhenInUseAuthorization];
// Significant Location Change location manager
self.significantLocationChangeLocationManager = [[CLLocationManager alloc] init];
self.significantLocationChangeLocationManager.delegate = self;
self.significantLocationChangeLocationManager.activityType = CLActivityTypeAutomotiveNavigation;
[self.significantLocationChangeLocationManager requestWhenInUseAuthorization];
// Start the managers
[self.standardLocationManager startUpdatingLocation];
[self.significantLocationChangeLocationManager startMonitoringSignificantLocationChanges];
我使用MWormhole来"调试"发生了什么。
唯一被调用的委托方法是:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways){
if (manager == self.significantLocationChangeLocationManager) {
[[WatchController sharedController]notify:@"starting slc loc manager"]; // call MWWormHole to debug
[self.significantLocationChangeLocationManager startMonitoringSignificantLocationChanges];
} else if (manager == self.standardLocationManager) {
[[WatchController sharedController]notify:@"starting standard loc manager"]; // call MWWormHole to debug
[self.standardLocationManager startUpdatingLocation];
}
}
}
在此委托方法中,status
已获得授权,因为我的监视应用程序中同时包含调试消息。
我的问题: