HackingWithSwift icon indicating copy to clipboard operation
HackingWithSwift copied to clipboard

Classic - Project 22: locationManager(_ didChangeAuthorization status: CLAuthorizationStatus) was deprecated in iOS 14.0

Open phatnguyen1006 opened this issue 3 years ago • 1 comments

Classic - Project 22: Detect a Beacon. I see alerts:

  • locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) was deprecated in iOS 14.0

  • locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) was deprecated in iOS 13.0

Maybe need to update below functions in HackingWithSwift/Classic/project22/Project22/ViewController.swift


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
  if status == .authorizedAlways {
	  if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
		  if CLLocationManager.isRangingAvailable() {
			  startScanning()
		  }
	  }
  }
}


func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {
    if beacons.count > 0 {
	    let beacon = beacons[0]
	    update(distance: beacon.proximity)
    } else {
	    update(distance: .unknown)
    }
}

to


func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
    if manager.authorizationStatus == .authorizedAlways {
        if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
		if CLLocationManager.isRangingAvailable() {
			startScanning()
		}
	}
    }
}

func locationManager(_ manager: CLLocationManager, didRange beacons: [CLBeacon], satisfying beaconConstraint: CLBeaconIdentityConstraint) {
    if beacons.count > 0 {
        let beacon = beacons[0]
        update(distance: beacon.proximity)
    } else {
        update(distance: .unknown)
    }
}

phatnguyen1006 avatar Dec 29 '21 16:12 phatnguyen1006

Im trying change functions in https://github.com/twostraws/HackingWithSwift/pull/68

phatnguyen1006 avatar Dec 29 '21 17:12 phatnguyen1006