If user disabled location services in privacy settings, how can I show this popup. Tap on settings button opens settings with privacy category, we can't do it using private api, so I think it is system popup. But what function or action will trigger it's appear? I think it may be called by system if location service was tracking when location was disabled. first second
CodePudding user response:
class let openSettingsURLString: String
Create a URL from this value and pass it to the open(_:options:completionHandler:)
method to launch the Settings app and display your app’s custom settings, if it has any.
// Create the URL that deep links to your app's custom settings.
if let url = URL(string: UIApplication.openSettingsURLString) {
// Ask the system to open that URL.
await UIApplication.shared.open(url)
}
CodePudding user response:
I guess the second pop up is not the iOS generated but custom one. You can check the location authorization status and then if location is off i.e denied or restricted in this case. So if it's denied or restricted then create a custom alert/action-sheet to show that pop up with title, subtile and button with option asking user to kindly go to setting and make location service on or just dismiss the alert/action sheet if user selects keep negative button i.e location service off button.
if CLLocationManager.locationServicesEnabled() {
print("Location service enabled")
switch CLLocationManager.authorizationStatus() {
case .notDetermined:
print("Location service not determined")
self.manager.requestWhenInUseAuthorization()
self.manager.startUpdatingLocation()
case .restricted, .denied:
// Disable location features
print("Location service DENIED")l
show that second alert/action sheet here.
case .authorizedWhenInUse, .authorizedAlways:
// Enable features that require location services here.
print("Full Access")
self.manager.startUpdatingLocation()
@unknown default:
print("unknown result")
}
} else {
print("location Services NOT Enabled")
}
}