2016-02-07 69 views
0

中的断言失败我试图用coreLocation在Apple Watch上获取用户当前位置。每当我运行-[CLLocationManager requestLocation],该应用程序退出并给出以下错误。Apple Watch coreLocation error *** [ - 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

应该有更多的错误消息告诉你什么是问题 – dan

+0

这个错误信息并没有什么意义,你在调试器中做了些什么来引起这个错误?也许从断点处记录某些东西? – dan

+0

它不会解决问题,但您现在应该能够看到真正的错误消息 – dan

回答

3

根据错误消息,'Delegate must respond to locationManager:didUpdateLocations:'我必须在我的委托中实现locationManager:didUpdateLocations:locationManager:didFailWithError:以便使用requestLocation。

0

我不知道我们是否可以在苹果手表中使用位置管理器。我认为我们需要回到父应用来使用手表连接来获取CLLocation。

+0

其实,我可以。在上面的评论中使用Dan的建议,我实现了委托方法,一切正常。换句话说,问题解决了! – NeilNie