Core Location changes in iOS 14

Core Location on iOS14

Hello, this time since the renovation of the Core Location around which was changed in iOS14 in the business, it will be a reminder to written. I didn't have many articles, so I hope it helps someone!

environment

macOS Catalina 10.15.6 Xcode Version 12.0.1

Deprecated

First, I investigated what became Deprecated. The target is a summary of things that can not be used with iOS 14 this time.

CLLocationManager Requesting Authorization for Location Services

class func authorizationStatus() -> CLAuthorizationStatus
//Returns the authentication status of the app for using the location information service.

Initiating Beacon Ranging Requests

func startRangingBeacons(in: CLBeaconRegion)
//Starts delivery of notifications for the specified beacon area.

func stopRangingBeacons(in: CLBeaconRegion)
//Stops the delivery of notifications for the specified beacon area.

var rangedRegions: Set<CLRegion>
//Stops the delivery of notifications for the specified beacon area.

Deferring Location Updates

class func deferredLocationUpdatesAvailable() -> Bool
//Returns a Boolean value that indicates whether the device supports lazy location updates.

func allowDeferredLocationUpdates(untilTraveled: CLLocationDistance, timeout: TimeInterval)
//Ask the location manager to defer delivery of location updates until the specified criteria are met.

func disallowDeferredLocationUpdates()
//Cancel the postponement of the location information update for this app.

CLLocationManagerDelegate

Responding to Authorization Changes

func locationManager(CLLocationManager, didChangeAuthorization: CLAuthorizationStatus)
//Notify delegates of approval status when the app creates a location manager and when the approval status changes
func locationManagerDidChangeAuthorization(CLLocationManager)
//Notify the delegate when the app creates a location manager and when the approval status changes.

Responding to Ranging Events

func locationManager(CLLocationManager, didRangeBeacons: [CLBeacon], in: CLBeaconRegion)
//Notifies the delegate that one or more beacons are in range.

func locationManager(CLLocationManager, rangingBeaconsDidFailFor: CLBeaconRegion, withError: Error)
//Notifies the delegate that an error has occurred while collecting the range information for a set of beacons.

The area around the beacon has changed quite a bit. By the way, I haven't used CLBeacon and I don't know what I can do, so I'll explore CLBeacon deeply next time. It may be useful for something like mountain climbing w

Main subject

Well, from here on, the main subject, What was particularly noticeable in this update was When permitting location information

--Accurate location information

I personally think that the addition of items is a major change.

It seems that Apple has thought about why this happened, so you can check it out. This time this --Accurate location information I would like to explain about this based on the Code.

Implementation

As a common implementation so far

let status = CLLocationManager.authorizationStatus() 
    switch status {
    case .authorizedWhenInUse:
    // ...
    case .authorizedAlways:
    // ... 
    case .denied:
    // ...
    case .notDetermined:
    // ...
    case .restricted:
    // ...
    case .authorized:
    // ...

I think I wrote the treatment for each status like this.

'authorizationStatus()' was deprecated in iOS 14.0

    @available(iOS, introduced: 4.2, deprecated: 14.0)
    open class func authorizationStatus() -> CLAuthorizationStatus

Since it was, authorizationStatus () cannot be used. However

public enum CLAuthorizationStatus : Int32 {}

You can use this, so I want to make sure you don't make a mistake.

As for this change

open class CLLocationManager : NSObject {
    // ...
    @available(iOS 14.0, *)
    open var authorizationStatus: CLAuthorizationStatus { get }
}

AuthorizationStatus has been newly added to CLLocationManager.

It's complicated here, so you should be careful.

The following Code is the main change of CLLocationManager.


open class CLLocationManager : NSObject {
    // ...
    @available(iOS 14.0, *)
    open var authorizationStatus: CLAuthorizationStatus { get }

    @available(iOS, introduced: 4.2, deprecated: 14.0)
    open class func authorizationStatus() -> CLAuthorizationStatus

    @available(iOS 14.0, *)
    open var accuracyAuthorization: CLAccuracyAuthorization { get }
    //A value that indicates the level of position accuracy that the app is allowed to use.

    @available(iOS 14.0, *)
    open var isAuthorizedForWidgetUpdates: Bool { get }
    //A Boolean value that indicates whether the widget is eligible to receive position updates.

    @available(iOS 14.0, *)
    open func requestTemporaryFullAccuracyAuthorization(withPurposeKey purposeKey: String, completion: ((Error?) -> Void)? = nil)
    //Request your permission to use location services completely accurately and temporarily.

    @available(iOS 14.0, *)
    open func requestTemporaryFullAccuracyAuthorization(withPurposeKey purposeKey: String)
    //Request your permission to use location services completely accurately and temporarily.
}

When separating status processing

func locationManager(CLLocationManager, didChangeAuthorization: CLAuthorizationStatus) {}

Because this is deprecated

func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {}

I will implement it using.

func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
 let status = manager.authorizationStatus
 switch status {
   case .authorizedAlways, .authorizedWhenInUse:
   // ...
   case .notDetermined, .denied, .restricted:
   // ...
   default: 
   // ...
 }
}

In this way, the processing for status is branched.

Next is about accurate location information

public enum CLAccuracyAuthorization : Int {
    case fullAccuracy = 0     //Accurate location information ON
    case reducedAccuracy = 1  //Accurate location information OFF
}

This is newly added.

   switch manager.accuracyAuthorization {
   case .fullAccuracy:
       print("Accurate location information")
   case .reducedAccuracy:
       print("Ambiguous location information")
   default:

   }

As an implementation, it is possible to branch in this way. To explain this change to non-engineers When I explained reducedAccuracy by the term [ambiguous location information], it understood. According to the official (DeepL Translator)

// The user has chosen to grant this application access to location information with reduced accuracy. // Region monitoring and beacon ranging are not available to the application. Other CoreLocation APIs // are available with reduced accuracy. // Location estimates will have a horizontalAccuracy on the order of about 5km. To achieve the // reduction in accuracy, CoreLocation will snap location estimates to a nearby point which represents // the region the device is in. Furthermore, CoreLocation will reduce the rate at which location // estimates are produced. Applications should be prepared to receive locations that are up to 20 // minutes old.

The user has chosen to allow this application access to inaccurate location information. Regional monitoring and beacon ranging are not available in the application. Other CoreLocation APIs Can be used with reduced accuracy. The horizontal accuracy of position estimation is on the order of about 5km. To achieve // CoreLocation snaps the position estimate to a nearby point to prevent inaccuracy. Specifies the region where the device is located. In addition, CoreLocation is the region where the device resides. I am making a quote. Prepare your application to receive up to 20 locations. Minutes have passed.

It is written like this.

The main thing I corrected in my work was to get accurate location information and use it in various ways, so this time I mainly made the corrections here.

Summary

This time, I focused on the changed part of Core Location. Since there are various patterns depending on the application, I think that there may be cases where the desired implementation can not be achieved only by the above correspondence, so I will paste the article that I referred to.

Privacy around location information further enhanced in iOS 14 [iOS14] WWDC 2020 Core Location New Element Precise

I referred to the above article. Not written in this article --How to use requestTemporaryFullAccuracyAuthorization --About info.plist --About Apple's Map app --Behavior of standard application, etc. --Others Etc. were described, so I thought it would be good to read them all together.

Apple official What's new in location Core Location

Thank you for reading.

Recommended Posts

Core Location changes in iOS 14
Changes in Mockito 2
Changes in mybatis-spring-boot-starter 2.1
Changes in mybatis-spring-boot-starter 1.3
Changes in Java 11
Changes in mybatis-spring-boot-starter 1.2
Major changes in Spring Framework 5.0 core functionality
Changes in JUnit5M4-> M5
Major changes in Spring Boot 1.5
Java version notation that changes in Java 10
Specify the java location in eclipse.ini
New in iOS14, Near by Interaction