首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >委托必须响应locationManager: didFailWithError :即使实现了didFailWithError方法

委托必须响应locationManager: didFailWithError :即使实现了didFailWithError方法
EN

Stack Overflow用户
提问于 2017-04-24 01:34:06
回答 1查看 3.3K关注 0票数 3

出于某种原因,Xcode认为我没有实现CLLocationManagerDelegate协议的CLLocationManagerDelegate方法

我看不出自己做错了什么,因为我真的是从另一个SO post复制过来的,它说这个didFailWithError方法已经为Swift 3更新了。

任何洞察力都将不胜感激!

代码

代码语言:javascript
复制
class OptionsViewController: UIViewController,
    CLLocationManagerDelegate {
var locationManager: CLLocationManager = CLLocationManager()

    override func viewDidLoad() {
//Ask user for location
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        
        //Use users current location if no starting point set
        if CLLocationManager.locationServicesEnabled() {
            if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse
                || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways {
                locationManager.requestLocation()
            }
            else{
                locationManager.requestWhenInUseAuthorization()
            }
        }
        else{
            //Alert user to open location service, bra bra bra here...
        }
    }

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("error:: \(error)")
    }
    
    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        print("didChangeAuthorization")
        if status == CLAuthorizationStatus.authorizedWhenInUse
            || status == CLAuthorizationStatus.authorizedAlways {
            locationManager.requestLocation()
        }
        else{
            //other procedures when location service is not permitted.
        }
    }
    
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print("Did update location called")
//        let locValue:CLLocationCoordinate2D = manager.location!.coordinate
//        print("locations = \(locValue.latitude) \(locValue.longitude)")
        if locations.first != nil {
            print("location:: (location)")
        }
        
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-25 01:39:09

我意识到它需要使用特定类型的Error (特别是Swift.Error) --这是正确的didFailWithError方法声明

代码语言:javascript
复制
func locationManager(_ manager: CLLocationManager, didFailWithError error: Swift.Error) {
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43578473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档