Commit 15e1a49d by Demid Merzlyakov

IOS-121: Fix ANR when device is locked while the location permissions dialog is shown.

It turned out that iOS native location permissions dialog disappears when the app goes into the background, without firing any callback. I added code that keeps track of wether the dialog is being shown or not, and if it is supposed to be shown, we re-show it again when the app gets back from the background.
parent 9037f1af
......@@ -102,6 +102,15 @@ internal class DeviceLocationMonitor: NSObject {
public let timeZoneIdentifier: String? = nil
}
public override init() {
super.init()
NotificationCenter.default.addObserver(self, selector: #selector(handleReturnFromBackground), name: UIApplication.didBecomeActiveNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
public typealias CurrentLocationCompletion = (LocationRequestResult) -> ()
public func useCurrentLocation(requestedFrom viewController: UIViewController, completion: @escaping CurrentLocationCompletion) {
......@@ -178,6 +187,18 @@ internal class DeviceLocationMonitor: NSObject {
viewController.present(alertGoToSettings, animated: true, completion: nil)
}
@objc
private func handleReturnFromBackground() {
// If the device is locked while the location permission dialog is shown, it disappears, and the app may end up in an unexpected state, waiting for a callback from DeviceLocationMonitor.
// So, if we were showing a permission dialog when the device was sent to background, we need to show it again when the app becomes active.
// This variable is not nil, if a permission dialog is shown.
if authorizationStatusChangeHandler != nil {
if CLLocationManager.authorizationStatus() == .notDetermined {
locationManager.requestWhenInUseAuthorization()
}
}
}
}
// MARK: - CLLocationManagerDelegate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment