dpa99c / cordova-plugin-request-location-accuracy

Cordova/Phonegap plugin for Android and iOS to request enabling/changing of Location Services by triggering a native dialog
96 stars 62 forks source link

iOS system dialog asking "turn on location services" does not fire cordova pause or resume events #60

Closed JeremyColton closed 5 years ago

JeremyColton commented 5 years ago

I'm submitting a bug report.

My iOS (cordova 4.1, iOS 11) app calls

cordova.plugins.locationAccuracy.request(function (success){ console.log("Successfully requested accuracy: "+success.message); }

  1. Current behaviour:

The iOS system dialog appears asking "Turn on Location Services to Allow to Determine Your Location". I have registered event handlers for 'pause' and 'resume'. But the 'pause' event is not fired when the native iOS dialog appears. Why not?

Also, when I click 'Cancel' the 'resume' event does not fire. Why not? Is the app not actually put in the background so the pause event doesn't fire?

  1. Expected behavior: The pause event is fired when the dialog appears or when the 'cancel' button is pressed and the app is brought to the foreground. The 'resume' event is fired when the 'cancel' button is pressed.

Environment information: Cordova CLI 7.0.1 Cordova iOS 4.1 iOS 11 cordova-plugin-request-location-accuracy version 2.2.3

Other plugins: cordova-labs-local-webserver 2.4.0 "CordovaLocalWebServer" cordova-labs-wkwebview-engine-localhost 0.5.0 "Cordova WKWebView Engine with http server (localhost) support" cordova-plugin-camera 2.2.0 "Camera" cordova-plugin-compat 1.0.0 "Compat" cordova-plugin-console 1.0.7 "Console" cordova-plugin-device 1.1.2 "Device" cordova-plugin-dialogs 1.2.1 "Notification" cordova-plugin-email-composer 0.8.3 "EmailComposer" cordova-plugin-facebook4 1.4.1 "Facebook Connect" cordova-plugin-file 3.0.0 "File" cordova-plugin-geolocation 2.0.1-dev "Geolocation" cordova-plugin-http 1.1.0 "SSL Pinning" cordova-plugin-inappbrowser 1.1.2-dev "InAppBrowser" cordova-plugin-media 1.0.1 "Media" cordova-plugin-network-information 1.1.0 "Network Information" cordova-plugin-request-location-accuracy 2.2.3 "Request Location Accuracy" cordova-plugin-screensize 1.3.1 "screensize" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.1 "StatusBar" cordova-plugin-wkwebview-engine 1.1.3 "Cordova WKWebView Engine" cordova-plugin-x-socialsharing 5.0.8 "SocialSharing" cordova.plugins.diagnostic 3.9.2 "Diagnostic" ionic-plugin-keyboard 1.0.8 "Keyboard" org.apache.cordova.startapp 0.3.0 "startApp" phonegap-plugin-push 1.5.2 "PushPlugin"

Mac OS 10.14.1 XCode 10.1

iPhone 8, running iOS 11

Related code: cordova.plugins.locationAccuracy.request(function (success){ console.log("Successfully requested accuracy: "+success.message); }

Console output when opening the native iOS dialog: locationManager::didFailWithError (null)

Console output when pressing 'cancel' button: active PushPlugin skip clear badge

dpa99c commented 5 years ago

This is the expected behaviour on iOS. The system dialog is shown as a UIAlert window in the view hierarchy of the application which made the request, hence the application never gets paused or therefore resumed when the dialog is shown. Only if the user pressing the "Settings" button which opens the Settings app on the Location Services page does the app which requested the dialog get paused in the background.

JeremyColton commented 5 years ago

Thanks for your fast reply. So can there be a callback when the user presses the 'Cancel' button? Otherwise the app has no way to know if anything happened effectively freezing it!

dpa99c commented 5 years ago

Unfortunately there's no way to create a callback since the native iOS system dialog doesn't provide any mechanism for this - we are limited by the functionality which Apple has deemed fit to give us. The system dialog is actually indirectly invoked by requesting location updates via the native location manager service.

The best you can do is to set a timeout before invoking the system dialog which re-checks if Location Services is on via diagnostic.isLocationEnabled(). Also if you start receiving location updates, you'll know that Location Services has been switched on.

JeremyColton commented 5 years ago

Ok, thanks for your great advice.