代码之家  ›  专栏  ›  技术社区  ›  Rob Md Fahim Faez Abir

CLFloor返回2146959360层?

  •  0
  • Rob Md Fahim Faez Abir  · 技术社区  · 5 年前

    我正在使用 CLLocationManager location 属性和检查 level floor ,如果有的话。文件显示如果它不能确定 地板 nil . 实际上,我得到了一个 CLFloor 水平

    lazy var locationManager: CLLocationManager = {
        let locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        return locationManager
    }()
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        switch CLLocationManager.authorizationStatus() {
        case .notDetermined: locationManager.requestWhenInUseAuthorization()
        case .denied:        redirectToSettings()
        default:             break
        }
    }
    
    @IBAction func didTapGetLocation(_ sender: Any) {
        updateLabels(for: locationManager.location)
    }
    
    func updateLabels(for location: CLLocation?) {
        guard let location = location else {
            floorLabel.text = "No location."
            return
        }
    
        if let floor = location.floor {
            let hexString = "0x" + String(format: "%08x", floor.level)
            floorLabel.text = "\(floor.level) (\(hexString))"
        } else {
            floorLabel.text = "No floor."
        }
    }
    

    ,与预期一样,模拟器也是如此。

    怎么回事?

    1 回复  |  直到 5 年前
        1
  •  2
  •   Rob Md Fahim Faez Abir    5 年前

    如果你打电话,这个问题就会消失 startUpdatingLocation . 如果你这么做,那么 floor nil . 这个 CLFloor level 值2146959360(0x7FF80000)仅在查询 location CLLocationManager 没有第一次打电话 .

    位置 应该是 水平

    看到了吗 this repo 例如bug的表现和如何调用的演示 作品。

    enter image description here

    推荐文章