Jyo*_*thi 20 location objective-c apple-watch watchkit watchos-2
我需要在watchOS 2中获取WatchKit App的用户当前位置.我该怎么办?
dan*_*ard 23
其他答案不正确.您可以直接在手表上请求位置以观看OS2.调用可用的方法requestLocation.它允许您请求单个位置更新.
例如
#import <CoreLocation/CoreLocation.h>
@interface className : WKInterfaceController<CLLocationManagerDelegate>
Run Code Online (Sandbox Code Playgroud)
然后你想要求位置:
self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestLocation];
Run Code Online (Sandbox Code Playgroud)
然后,您将通过以下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
}
Run Code Online (Sandbox Code Playgroud)
查看WWDC15视频"核心位置的新功能" - https://developer.apple.com/videos/wwdc/2015/?id=714
