Coder Social home page Coder Social logo

Comments (20)

dpa99c avatar dpa99c commented on June 4, 2024 2

As far as I know, it's not possible to open a sub-page (e.g. Location Sevices) in the iOS settings app. The best that can be done, is to switch to the settings page for a specific app which is what switchToSettings() does on iOS.

I don't know of any other apps that are able to do this, but it's possible Apple's own apps can do it since they have access to private APIs that the rest of us are not privileged to.

See stackoverflow discussions here and here

from cordova-diagnostic-plugin.

juukie avatar juukie commented on June 4, 2024 1

FYI, this is what I've done:

var confirm = $ionicPopup.confirm({
  title: 'Location',
  template: 'Enable locationservices?',
  cancelText: 'Nope',
  okText: 'Yup'
});

confirm.then(function (confirmed) {
  if (confirmed) {
    try {
      if (ionic.Platform.isIOS()) {
        cordova.plugins.diagnostic.switchToSettings();
      } else {
        cordova.plugins.diagnostic.switchToLocationSettings();
      }
    } catch (err) {}
  }
});

On IOS 9.3 it takes me to the settings of the application.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

There's at least one non-Apple app that I know of that can do that. "Speedtest" by Ookla is an example:
screen shot 2016-01-28 at 13 40 07

Maybe to much to ask from cordova-diagnostic-plugin to find the desired solution but I am just looking for ideas / alternatives since it does seem doable.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

Interesting. It may be that it's possible but just not well documented (that would be very like Apple). The actual implementation to do it wouldn't be very hard, it just knowing what the appropriate URL string is to open... maybe a question on stackoverflow is in order...

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

I've had a quick glance at couple of SO threads but sadly nothing points to the right solutions. IMHO it'd be a much more user friendly way of achieving the goal as it is the page where one actually enables device location. Android beats it in this respect.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

Ah, I think I understand. That dialog and it's buttons you showed in the screenshot are auto-generated by the iOS CLLocationManager (see here). Therefore it's using a private API which is not accessible to non-Apple apps. That dialog is shown in response to an app requesting to use location if location services is currently turned off. So it's not something the plugin can directly hook into to display the Location Settings page.

However, this dialog should be shown if you app requests a location and Location Services is switched off.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

Other than via that auto-generated dialog, if you want the user to get to the Location Settings page, the best you can currently do on iOS is to popup a dialog instructing the user what to do, then use cordova.plugins.diagnostic.switchToSettings to switch to the Settings app.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

So, does cordova-diagnostic-plugin (or cordova-plugin-geolocation) actually have the capability to pop up the auto-generated dialog / uses the iOS CLLocationManager when needed?
Trying to connect end to end here...

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

You'd use cordova-plugin-geolocation to request a position - if location services is turned off, this should result in displaying the system-generated dialog. See the example app source code for an example.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

Sure @dpa99c , I'll give it a go again even though I went through that possibility by experimenting and don't actually remember the same kind of system dialog popping up.
Thanks or the help so far.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

I basically came to the same conclusion when it comes to using cordova-plugin-geolocation's getCurrentPosition. Its error function will be called if Location Services are disabled at the moment of execution.
iOS doesn't pop any (desired) dialog with a Settings button in it.
Android behaves in the same way, except that as a mid step I get a dialog asking for a permission to use location. Naturally, even if I choose "Allow", the getCurrentPosition error function will be called since device location is off.

I can only see at this either as a deficiency or a bug in the cordova-plugin-geolocation plugin.

Feel free to close this discussion here. It's a real X-Files. I might write in the Cordova dev mailing list to see if anyone knows of a cure / way forward.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

Yes, you're right, that actually is the behaviour of cordova-plugin-geolocation, come to think of it. And if you look at its iOS source code, you can see that if location services is turned off, it just raises an error without even trying to request a location via the location manager (which is what would trigger that dialog) - see here.

So it's not a bug, but intentional behaviour. If you want different behaviour, you'll either have to fork cordova-plugin-geolocation and change its behaviour, or create your own small plugin which makes a direct request to the native location manager to start updating location ([locationManager startUpdatingLocation]), which will trigger the dialog. But I think this is beyond the scope of cordova-diagnostic-plugin.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

Filed a feature request over at https://issues.apache.org/jira/browse/CB-10478

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

@juukie

On IOS 9.3 it takes me to the settings of the application.

This is the expected behaviour. Note that (as I've said above): it's not possible to open a sub-page (e.g. Location Sevices) in the iOS settings app. The best that can be done, is to switch to the settings page for a specific app which is what switchToSettings() does on iOS.

from cordova-diagnostic-plugin.

juukie avatar juukie commented on June 4, 2024

Yep it's a nice solution this way because the user will be able to allow locationservices for the app right away 👍

from cordova-diagnostic-plugin.

rojarohini avatar rojarohini commented on June 4, 2024

can any one suggest me , i am unable check location services in ios turn on or off using this plugin

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

@rojarohini it's not possible to programatically turn on/off Location Services on iOS or even open a sub-page (e.g. Location Sevices) in the iOS settings app. The best that can be done, is to switch to the settings page for a specific app which is what switchToSettings() does on iOS.
Before doing so, you can instruct the user how to manually navigate and enable location for the app.

from cordova-diagnostic-plugin.

rojarohini avatar rojarohini commented on June 4, 2024

@dpa99c actually i want to know few things like

  1. Local Services settings in my ios mobile turn on or off.
  2. if off then i need to navigate to settings.
    i have tried like switchToSettings() initially only without testing services on or off but not working, can you give me brief description and suggestion if i am trying any thing wrong.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 4, 2024

@zarko-tg I got around to updating cordova-plugin-request-location-accuracy - v2.0.0 now enables a direct location request to be made which triggers the native iOS dialog.

from cordova-diagnostic-plugin.

zarko-tg avatar zarko-tg commented on June 4, 2024

Much appreciated @dpa99c, I should be trying it out soonish.

from cordova-diagnostic-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.