0

This is how I'm showing Loction alert pop-up if location is not enabled.

override func viewDidAppear(_ animated: Bool) {
   super.viewDidAppear(animated)
   LocationManager.shared.requestLocationAuthorization()
}


class LocationManager: NSObject, CLLocationManagerDelegate {

    static let shared = LocationManager()
    private var locationManager: CLLocationManager = CLLocationManager()
    private var requestLocationAuthorizationCallback: ((CLAuthorizationStatus) -> Void)?

    public func requestLocationAuthorization() {
        self.locationManager.delegate = self
        let currentStatus = CLLocationManager.authorizationStatus()

        // Only ask authorization if it was never asked before
        guard currentStatus == .notDetermined else { return }

        if #available(iOS 13.4, *) {
            self.requestLocationAuthorizationCallback = { status in
                if status == .authorizedWhenInUse {
                    self.locationManager.requestAlwaysAuthorization()
                }
            }
            self.locationManager.requestWhenInUseAuthorization()
        } else {
            self.locationManager.requestAlwaysAuthorization()
        }
    }
    // MARK: - CLLocationManagerDelegate
    public func locationManager(_ manager: CLLocationManager,
                                didChangeAuthorization status: CLAuthorizationStatus) {
        self.requestLocationAuthorizationCallback?(status)
    }
}

Now with this code, I get the location alert with a map within it like so..

enter image description here

But I want an alert that looks something like this:

enter image description here

How can I achieve this?

user987654
  • 19
  • 5
  • You can use Default UIAlert controller and set preferred style as action sheet you can check this answer how to do it https://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift/33340757#33340757 – Mohammad Daihan Oct 20 '22 at 10:48

0 Answers0