我尝试使用coreLocation在Apple Watch上获取用户当前位置。每当我运行-[CLLocationManager requestLocation]
时,应用程序退出并发出以下错误。
2016-02-07 16:38:39.392 Placescope Apple Watch Extension[6255:1471552] *** Assertion failure in -[CLLocationManager requestLocation], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1861.3.25.31/Framework/CoreLocation/CLLocationManager.m:816 2016-02-07 16:38:39.395 Placescope Apple Watch Extension[6255:1471552] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Delegate must respond to locationManager:didUpdateLocations:' *** First throw call stack: ( 0 CoreFoundation 0x00bb9fc4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00671df4 objc_exception_throw + 50 2 CoreFoundation 0x00bb9e5a +[NSException raise:format:arguments:] + 138 3 Foundation 0x0029a008 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 118 4 CoreLocation 0x0013a4f9 CLClientGetCapabilities + 12683 5 Placescope Apple Watch Extension 0x0002edbf -[Recommendations awakeWithContext:] + 447 6 WatchKit 0x000c2930 _WKInterfaceControllerCreateClass + 482 7 WatchKit 0x000af002 __48-[SPRemoteInterface handlePlist:fromIdentifier:]_block_invoke_2 + 470 8 WatchKit 0x000aebb9 __48-[SPRemoteInterface handlePlist:fromIdentifier:]_block_invoke + 1245 9 libdispatch.dylib 0x0415a71b _dispatch_call_block_and_release + 15 10 libdispatch.dylib 0x041783fd _dispatch_client_callout + 14 11 libdispatch.dylib 0x04160fbe _dispatch_main_queue_callback_4CF + 689 12 CoreFoundation 0x00b066fe __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14 13 CoreFoundation 0x00ac49a4 __CFRunLoopRun + 2356 14 CoreFoundation 0x00ac3db6 CFRunLoopRunSpecific + 470 15 CoreFoundation 0x00ac3bcb CFRunLoopRunInMode + 123 16 Foundation 0x0022dac1 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 308 17 Foundation 0x002d499d -[NSRunLoop(NSRunLoop) run] + 82 18 libxpc.dylib 0x0448206f _xpc_objc_main + 486 19 libxpc.dylib 0x04484dce xpc_main + 215 20 Foundation 0x003fe3cd service_connection_handler + 0 21 PlugInKit 0x035f1232 -[PKService run] + 582 22 WatchKit 0x000d1549 main + 146 23 libdyld.dylib 0x0419dad5 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
这是我的代码:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager requestWhenInUseAuthorization];
[locationManager requestLocation];
如果您有更好的方式来获取用户的位置,请告诉我。
答案 0 :(得分:5)
根据错误消息'Delegate must respond to locationManager:didUpdateLocations:'
,我必须在我的委托中实施locationManager:didUpdateLocations:
和locationManager:didFailWithError:
才能使用requestLocation。
答案 1 :(得分:0)
我不知道我们是否可以在Apple Watch中使用位置管理器。我认为我们需要回到父应用程序以使用手表连接来获取CLLocation。