iOS 如何防止多次呼叫didUpdateLocations方法
阿新 • • 發佈:2019-02-02
原貼
http://www.aichengxu.com/diannao/72340.htm
1:判斷didUpdateLocations這個方法呼叫幾次 _currLocationl = [locations lastObject]; NSString *loc=[NSString stringWithFormat:@"%f,%f",_currLocationl.coordinate.latitude,_currLocationl.coordinate.longitude]; NSTimeInterval locationAge = -[_currLocationl.timestamp timeIntervalSinceNow]; if (locationAge > 1.0){//如果呼叫已經一次,不再執行 return; }else{ UZGPersonalSetting *s=[UZGPersonalSetting getInstance]; if (nil == s.session) {//已登入 [_locateShop initHttpLocateShopWithType:@"GPS" andAddress:loc alert:@"" GPSData:loc]; }else{ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]){ _locationViewMa = [UZGStartLocationViewManager sharedAlertViewManager]; _locationViewMa.delegate=self; [_locationViewMa show]; } [_locateShop initHttpLocateShopWithType:@"NAME" andAddress:_locateAddress alert:@"" GPSData:loc]; } } 2:判斷是否定位成功了 if (_currLocationl.horizontalAccuracy > 0) {//已經定位成功了 [_locationManager stopUpdatingLocation]; }else{ }