Skip to content

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

@phatnguyen1006

Description

@phatnguyen1006

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)
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions