From 27a1c1a4b34912b7420e86be058abc2d74fa4238 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 27 Nov 2019 20:39:54 +0400 Subject: [PATCH] Fix location picker crash --- .../Sources/LocationPickerController.swift | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/submodules/LocationUI/Sources/LocationPickerController.swift b/submodules/LocationUI/Sources/LocationPickerController.swift index 064dbc1fc6..7f57b8f30a 100644 --- a/submodules/LocationUI/Sources/LocationPickerController.swift +++ b/submodules/LocationUI/Sources/LocationPickerController.swift @@ -95,29 +95,8 @@ public final class LocationPickerController: ViewController { strongSelf.searchNavigationContentNode?.updatePresentationData(strongSelf.presentationData) strongSelf.navigationItem.rightBarButtonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationCompactSearchIcon(strongSelf.presentationData.theme), style: .plain, target: strongSelf, action: #selector(strongSelf.searchPressed)) - strongSelf.controllerNode.updatePresentationData(presentationData) - }) - - self.permissionDisposable = (DeviceAccess.authorizationStatus(subject: .location(.send)) - |> deliverOnMainQueue).start(next: { [weak self] next in - guard let strongSelf = self else { - return - } - switch next { - case .notDetermined: - DeviceAccess.authorizeAccess(to: .location(.send), locationManager: strongSelf.locationManager, presentationData: strongSelf.presentationData, present: { c, a in - strongSelf.present(c, in: .window(.root), with: a) - }, openSettings: { - strongSelf.context.sharedContext.applicationBindings.openSettings() - }) - case .denied: - strongSelf.controllerNode.updateState { state in - var state = state - state.forceSelection = true - return state - } - default: - break + if strongSelf.isNodeLoaded { + strongSelf.controllerNode.updatePresentationData(presentationData) } }) @@ -310,6 +289,29 @@ public final class LocationPickerController: ViewController { self.displayNode = LocationPickerControllerNode(context: self.context, presentationData: self.presentationData, mode: self.mode, interaction: interaction) self.displayNodeDidLoad() + + self.permissionDisposable = (DeviceAccess.authorizationStatus(subject: .location(.send)) + |> deliverOnMainQueue).start(next: { [weak self] next in + guard let strongSelf = self else { + return + } + switch next { + case .notDetermined: + DeviceAccess.authorizeAccess(to: .location(.send), locationManager: strongSelf.locationManager, presentationData: strongSelf.presentationData, present: { c, a in + strongSelf.present(c, in: .window(.root), with: a) + }, openSettings: { + strongSelf.context.sharedContext.applicationBindings.openSettings() + }) + case .denied: + strongSelf.controllerNode.updateState { state in + var state = state + state.forceSelection = true + return state + } + default: + break + } + }) } override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {