我正在使用 swift 3.0创建一个应用程序,但我很快遇到了一个问题.我设置必要的功能来请求使用位置的权限,但每次运行应用程序时都会出现同样的错误…
VIEwcontroller.h
import UIKitimport MapKitclass VIEwController: UIVIEwController { let locationManager = CLLocationManager() overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.requestWhenInUseAuthorization() locationManager.requestLocation() } overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. }}extension VIEwController : CLLocationManagerDelegate { private func locationManager(manager: CLLocationManager,dIDChangeAuthorizationStatus status: CLAuthorizationStatus) { if status == .authorizeDWhenInUse { locationManager.requestLocation() } } private func locationManager(manager: CLLocationManager,dIDUpdateLocations locations: [CLLocation]) { if locations.first != nil { print("location:: (location)") } } private func locationManager(manager: CLLocationManager,dIDFailWithError error: NSError) { print("error:: (error)") }}
错误:
2016-10-31 16:12:11.436192 Assemble[57741:2743477] bundleID: com.AssembleTm.Assemble,enable_level: 0,persist_level: 0,propagate_with_activity: 02016-10-31 16:12:11.437006 Assemble[57741:2743477] subsystem: com.apple.siri,category: Intents,enable_level: 1,persist_level: 1,default_ttl: 0,info_ttl: 0,deBUG_ttl: 0,generate_symptoms: 0,enable_oversize: 0,privacy_setting: 0,enable_private_data: 02016-10-31 16:12:11.524494 Assemble[57741:2743668] subsystem: com.apple.UIKit,category: HIDEventFiltered,enable_oversize: 1,privacy_setting: 2,enable_private_data: 02016-10-31 16:12:11.526709 Assemble[57741:2743668] subsystem: com.apple.UIKit,category: HIDEventIncoming,enable_private_data: 02016-10-31 16:12:11.561488 Assemble[57741:2743658] subsystem: com.apple.BaseBoard,category: MachPort,enable_private_data: 02016-10-31 16:12:11.638717 Assemble[57741:2743477] subsystem: com.apple.UIKit,category: Statusbar,enable_private_data: 02016-10-31 16:12:11.744 Assemble[57741:2743477] *** Assertion failure in -[CLLocationManager requestLocation],/buildroot/library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-2100.0.12/Framework/CoreLocation/CLLocationManager.m:8652016-10-31 16:12:11.855 Assemble[57741:2743477] *** Terminating app due to uncaught exception 'NSInternalinconsistencyException',reason: 'Delegate must respond to locationManager:dIDUpdateLocations:'*** First throw call stack:( 0 CoreFoundation 0x000000010a58d34b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010873b21e objc_exception_throw + 48 2 CoreFoundation 0x000000010a591442 +[NSException raise:format:arguments:] + 98 3 Foundation 0x0000000106799edd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 CoreLocation 0x0000000106291523 CLClIEntGetCapabilitIEs + 13233 5 Assemble 0x00000001061e1976 _TFC8Assemble14VIEwController11vIEwDIDLoadfT_T_ + 294 6 Assemble 0x00000001061e19e2 _TToFC8Assemble14VIEwController11vIEwDIDLoadfT_T_ + 34 7 UIKit 0x000000010708f06d -[UIVIEwController loadVIEwIfrequired] + 1258 8 UIKit 0x000000010708f4a0 -[UIVIEwController vIEw] + 27 9 UIKit 0x0000000106f59045 -[UIWindow addRootVIEwControllerVIEwIfPossible] + 71 10 UIKit 0x0000000106f59796 -[UIWindow _setHIDden:forced:] + 293 11 UIKit 0x0000000106f6d0a9 -[UIWindow makeKeyAndVisible] + 42 12 UIKit 0x0000000106ee6259 -[UIApplication _callinitializationDelegatesForMainScene:TransitionContext:] + 4818 13 UIKit 0x0000000106eec3b9 -[UIApplication _runWithMainScene:TransitionContext:completion:] + 1731 14 UIKit 0x0000000106ee9539 -[UIApplication workspaceDIDEndTransaction:] + 188 15 FrontBoardServices 0x000000010e1cf76b __FBSSERIALQUEUE_IS_CALliNG_OUT_TO_A_BLOCK__ + 24 16 FrontBoardServices 0x000000010e1cf5e4 -[FBSSerialQueue _performNext] + 189 17 FrontBoardServices 0x000000010e1cf96d -[FBSSerialQueue _performNextFromrunLoopSource] + 45 18 CoreFoundation 0x000000010a532311 __CFRUNLOOP_IS_CALliNG_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 19 CoreFoundation 0x000000010a51759c __CFRunLoopDoSources0 + 556 20 CoreFoundation 0x000000010a516a86 __CFRunLoopRun + 918 21 CoreFoundation 0x000000010a516494 CFRunLoopRunspecific + 420 22 UIKit 0x0000000106ee7db6 -[UIApplication _run] + 434 23 UIKit 0x0000000106eedf34 UIApplicationMain + 159 24 Assemble 0x00000001061e3fcf main + 111 25 libdyld.dylib 0x000000010af5b68d start + 1)libc++abi.dylib: terminating with uncaught exception of type NSException(lldb)
我是swift 3.0的新手,但是我找不到任何关于如何解决这个问题的事情(我在stackoverflow上查了一下但是他们给出的答案并没有帮助我…)
解决方法 您使用的是xcode8和swift3,但您的委托方法是从swift复制的.2.更改您的委托方法,如下所示.extension VIEwController : CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager,dIDFailWithError error: Error) { print("error:: \(error.localizedDescription)") } func locationManager(_ manager: CLLocationManager,dIDChangeAuthorization status: CLAuthorizationStatus) { if status == .authorizeDWhenInUse { locationManager.requestLocation() } } func locationManager(_ manager: CLLocationManager,dIDUpdateLocations locations: [CLLocation]) { if locations.first != nil { print("location:: (location)") } }}总结
以上是内存溢出为你收集整理的代表必须响应locationManager:didUpdateLocations swift eroor全部内容,希望文章能够帮你解决代表必须响应locationManager:didUpdateLocations swift eroor所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)