我需要为 watchOS 2 中的 WatchKit 应用获取用户当前位置。我该怎么做?
最佳答案
其他答案不正确。您可以直接在 watch OS2 watch 上请求位置。可用的方法称为 requestLocation
。它允许您请求单个位置更新。
例如
#import <CoreLocation/CoreLocation.h>
@interface className : WKInterfaceController<CLLocationManagerDelegate>
然后你要请求位置的地方:
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestLocation];
然后您将在以下 CLLocationManagerDelegate
方法之一中获得单个回调。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
// Callback here with single location if location succeeds
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
// Error here if no location can be found
}
观看 WWDC15 视频“核心位置的新功能”- https://developer.apple.com/videos/wwdc/2015/?id=714
关于objective-c - 如何在 watchOS 2 中获取当前位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31669634/