Giter Club home page Giter Club logo

Comments (11)

Shakti-Sharma avatar Shakti-Sharma commented on June 28, 2024 3

I tried

var locationEnabled;
function checkLocationState(){
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
locationEnabled = enabled;
}, onError);
}
document.addEventListener('resume', checkLocationState, false);
document.addEventListener('deviceready', checkLocationState, false);

but on coming back it does not trigger the resume event.

Now for the purpose of solution, i am putting a hack, like adding a timer in the app to check wheather location is on or not.

I am using ionic framework

Regard
Shakti

from cordova-diagnostic-plugin.

littlegit avatar littlegit commented on June 28, 2024 1

Solution: https://www.npmjs.com/package/cordova.plugins.diagnostic#registerlocationstatechangehandler

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 28, 2024

I could extend switchToLocationSettings to support a Javascript success callback, however when switchToLocationSettings() is called, the Cordova app is switched out into the background when the settings app is switched into the foreground, so the callback wouldn't be executed until the Cordova app is resumed. And in which case, you may as well re-check the location settings when the Cordova app is resumed; this will then also work if the user manually puts your app in the background (e.g using Home button), changes the location settings then returns to your app (this is the approach I've used in my apps).

For example:

var locationEnabled;
function checkLocationState(){
    cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
        locationEnabled = enabled;
    }, onError);
}
document.addEventListener('resume', checkLocationState, false);
document.addEventListener('deviceready', checkLocationState, false);

Note that on Android it's possible to change location settings without putting the app into the background using the quick settings menu via the status bar pull down. Because the app remains in the foreground, the resume event is not fired, so your app may remain unaware of the change. The approach I've taken in my apps is to re-check the location settings state after the first call to the positionError handler function for navigator.geolocation.watchPosition. This way, if the user turns off location settings while the app is in the foreground, the positionError handler will be called and my app will pick up the changed setting.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 28, 2024

Is this still an issue or can it be closed?

from cordova-diagnostic-plugin.

Shakti-Sharma avatar Shakti-Sharma commented on June 28, 2024

On hitting back button from location screen button, does not trigger any resume and deviceready event, Event i didnt get call back

cordova.plugins.diagnostic.switchToLocationSettings(function(success){ console.log(success);
}, function(error){
console.error("The following error occurred: "+error);
});

It is not solved yet. Although on registring for the ready and resume event open it on the application open.

Please suggest some help.

Thanks in advance.

from cordova-diagnostic-plugin.

Shakti-Sharma avatar Shakti-Sharma commented on June 28, 2024

screenshot_20161129-193150-1

Following back button in the bottom will be tigger any thing.
How to i handle it that the back button is pressed.

resume and deviceready event is not fired on hitting the back button.

Please Help.

from cordova-diagnostic-plugin.

Shakti-Sharma avatar Shakti-Sharma commented on June 28, 2024

@paulogr Plz help and open this issue.

from cordova-diagnostic-plugin.

dpa99c avatar dpa99c commented on June 28, 2024

@Shakti-Sharma This issue is resolved: as explained above, the switchToLocationSettings() function does not accept a callback function as a parameter due to the fact that the app will be immediately paused when the function is called, so the callback would not be executed until the app is resumed. And therefore, you may as well use the Cordova "resume" event to be notified. Using the back button in Android to return to the app does cause Cordova to fire the "resume" event as Android restores the activity to the foreground. For reference, please see the example project which makes use of the resume event in this way.

from cordova-diagnostic-plugin.

sidgujrathi avatar sidgujrathi commented on June 28, 2024

I am having same issue with iOS, I am listening for both "resume" and "deviceReady" events but none of the are triggered if user uses back button from settings, although it does triggered if users go to recent app and then selects app.

from cordova-diagnostic-plugin.

carherco avatar carherco commented on June 28, 2024

@littlegit That was the solution. Thanks!!!!

from cordova-diagnostic-plugin.

kapilSoni101 avatar kapilSoni101 commented on June 28, 2024

@littlegit sir i will check but after click mobile back button registerLocationStateChangeHandler is not trigger in my case ?

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.