我试图通过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
This is my code:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager requestWhenInUseAuthorization];
[locationManager requestLocation];
如果您有更好的获取用户位置的方法,也请告诉我。
最佳答案
根据错误消息,'Delegate must respond to locationManager:didUpdateLocations:'
我必须在我的委托中实现locationManager:didUpdateLocations:
和locationManager:didFailWithError:
才能使用requestLocation。
关于ios - Apple Watch coreLocation错误***-[CLLocationManager requestLocation]中的断言失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35258894/