2016-02-07 85 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