小编Per*_*los的帖子

didUpdateLocations委托方法重复一次随机次数

我在我的方法didUpdateLocations中获得用户的经度和经度.如果允许位置,我调用一个接受纬度,经度参数并调用webservice的方法,否则我会显示一个UIAlertView.

问题是:iOS随机调用我的locationManager委托方法.所以我的网络服务被多次调用......我该如何解决?

当我呼叫该位置时,验证是否允许...我在上一个屏幕中发出请求:

    // GET LOCATION
    self.initializeWaitingScreen()
    if( CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse ||
        CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways){
            self.locationManager.delegate = self
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
            self.locationManager.startUpdatingLocation()
    } else {
        let loginFailAlert: UIAlertView = UIAlertView(title: "Localisation refusée", message: "Vos fonctionnalités sont restreintes, pour accéder à l'application complète, veuillez activer la localisation", delegate: self, cancelButtonTitle: "OK")
        loginFailAlert.show()
        self.initializeUIComponent()
        self.initializeDataWithWebServiceWithoutLocation()
    }
Run Code Online (Sandbox Code Playgroud)

我的locationManager方法:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
            var lon = manager.location.coordinate.longitude.description
            var lat = manager.location.coordinate.latitude.description
            self.locationManager.stopUpdatingLocation()
            self.initializeDataWithWebServiceWithLocation(lon, _lat: lat)
            self.initializeUIComponent()
}
Run Code Online (Sandbox Code Playgroud)

self.initializeDataWithWebServiceWithLocation(lon, _lat: lat) 取经度和纬度,并将其交给我调用webservices的方法.

cllocationmanager cllocation ios swift

2
推荐指数
1
解决办法
1757
查看次数

标签 统计

cllocation ×1

cllocationmanager ×1

ios ×1

swift ×1