cordovaionic-frameworkngcordovaionic-v1

Check if Mobile Device has Automatic Time Zone enabled using ngCordova


Ionic v1 app needs to check if the Mobile Device (Android or iOS) has Automatic Time Zone enabled, how can I do that? I imagine it's done using ngCordova.

For some actions, Automatic Time Zone has to be enabled so the server will receive real date and time instead of fake ones. I won't allow the user to proceed if it's disabled.


Solution

  • I have created this ngcordova plugin to do that, at the moment it only supports Android. iOS is not supported because it doesn't expose iPhone's Date and Time settings programatically.

    Usage

    window.VerifyAutomaticDateTimeZone.isAutomaticChecked(function(isIt){
      if (isIt == 'true') {
            // do something
        } else {
            // do something else
        }
    });
    

    In case window.VerifyAutomaticDateTimeZone is undefined, wrap the call with $ionicPlatform.ready or ionic.Platform.ready

    $ionicPlatform.ready(function(){
        // code here...
    });