Ons Notification Yes no



  • Hi Guys!
    I have never used ons.notification.confirm
    Yes i’m not perfect lol

    And I want to replace in the code below the basic CONFIRM from Javascript (Is too old)
    But i’m having problem with callback function . Any advice!

    <script>
            function checkConnection() {
    
                // Wait for device API libraries to load
                //
                document.addEventListener("deviceready", onDeviceReady, false);
    
                // device APIs are available
                //
                function onDeviceReady() {
                    checkConnection();
                }
    
                var networkState = navigator.connection.type;
    
                var states = {};
                states[Connection.UNKNOWN] = 'Unknown connection';
                states[Connection.ETHERNET] = 'Ethernet connection';
                states[Connection.WIFI] = 'WiFi connection';
                states[Connection.CELL_2G] = 'Cell 2G connection';
                states[Connection.CELL_3G] = 'Cell 3G connection';
                states[Connection.CELL_4G] = 'Cell 4G connection';
                states[Connection.CELL] = 'Cell generic connection';
                states[Connection.NONE] = 'No network connection';
                if ((states[networkState]) == states[Connection.NONE]) {
                    if (confirm('No internet connection available ')) {
                        if (typeof cordova.plugins.settings.openSetting != undefined)
                            cordova.plugins.settings.openSetting("wifi", function () { console.log("Open the settings") }, function () { console.log("error to acess") });
    
                    } else {
                        navigator.app.exitApp();
                    }
    
                    navigator.app.exitApp();
                }
            }
    
            checkConnection();
        </script>
    
    ons.notification.confirm({
              message: 'Do you want to change your settings?',
              title: 'No internet connection available',
              buttonLabels: ['Yes', 'No'],
              animation: 'none',
              primaryButtonIndex: 1,
              cancelable: false,
              callback: function() {
                if( ){
                
                    ons.notification.confirm({message: 'Open the settings.',title: ' Lets go',buttonLabels: ['Ok'],cancelable: false});
                }
              }
        });
    


  • Try this:

    ons.notification.confirm({
              message: 'Do you want to change your settings?',
              title: 'No internet connection available',
              buttonLabels: ['Yes', 'No'],
              animation: 'none',
              primaryButtonIndex: 1,
              cancelable: false,
               callback: function(index) {
                if(index==0){            
                    ons.notification.confirm({message: 'Open the settings.',title: ' Lets go',buttonLabels: ['Ok'],cancelable: false});
                }
              }
        });
    


  • I didn’t get error, but now the app doesn’t check the internet agggghhh

     <script>
            function checkConnection() {
    
                // Wait for device API libraries to load
                //
                document.addEventListener("deviceready", onDeviceReady, false);
    
                // device APIs are available
                //
                function onDeviceReady() {
                    checkConnection();
                }
    
                var networkState = navigator.connection.type;
    
                var states = {};
                states[Connection.UNKNOWN] = 'Unknown connection';
                states[Connection.ETHERNET] = 'Ethernet connection';
                states[Connection.WIFI] = 'WiFi connection';
                states[Connection.CELL_2G] = 'Cell 2G connection';
                states[Connection.CELL_3G] = 'Cell 3G connection';
                states[Connection.CELL_4G] = 'Cell 4G connection';
                states[Connection.CELL] = 'Cell generic connection';
                states[Connection.NONE] = 'No network connection';
                if ((states[networkState]) == states[Connection.NONE]) {
                    ons.notification.confirm({
                        message: 'Do you want to change your settings?',
                        title: 'No internet connection available',
                        buttonLabels: ['Yes', 'No'],
                        animation: 'none',
                        primaryButtonIndex: 1,
                        cancelable: false,
                        callback: function (index) {
                            if (index == 0) {
                                if (typeof cordova.plugins.settings.openSetting != undefined)
                                    cordova.plugins.settings.openSetting("wifi", function () {
                                        console.log("Open the settings")
                                    }, function () {
                                        console.log("error to acess")
                                    });
                                ons.notification.confirm({
                                    message: 'Open the settings.',
                                    title: ' Lets go',
                                    buttonLabels: ['Ok'],
                                    cancelable: false
                                });
                            } else {
                                navigator.app.exitApp();
                            }
                            navigator.app.exitApp();
                        }
                    })
                }
            } ;
        </script>
    


  • This post is deleted!


  • @Leonardo-Augusto I rewrote what should work:

        document.addEventListener("deviceready", onDeviceReady, false);
    
        function onDeviceReady() {
            checkConnection();
        }
       
            function checkConnection() {
    
                var networkState = navigator.connection.type;
    
                var states = {};
                states[Connection.NONE] = 'No network connection';
                
                if (states[networkState] == 'No network connection') {
                    ons.notification.confirm({
                          message: 'Do you want to change your settings?',
                          title: 'No internet connection available',
                          buttonLabels: ['Yes', 'No'],
                          animation: 'none',
                          primaryButtonIndex: 1,
                          cancelable: false,
                           callback: function(index) {
                            if(index==0){            
                                if (typeof cordova.plugins.settings.openSetting != undefined){
                                    cordova.plugins.settings.openSetting("wifi", function () { console.log("Open the settings") }, function () { console.log("error to acess") });
                                }
                            } else if(index==1) {
                                navigator.app.exitApp();
                          }
                    });
                }
            }
    

    Edit: Missed a closing }. Updated now. Let me know if this works.



  • Hey @Leonardo-Augusto in your second post in thread, the code is super faded. What happened? It is so light that you cannot even read it. Is this happening for other people as well?

    0_1458267954192_Untitled.png



  • @munsterlander said:

    Hey @Leonardo-Augusto in your second post in thread, the code is super faded. What happened? It is so light that you cannot even read it. Is this happening for other people as well?

    Lol its UI EFFECT , i don’t know… Yes! to me is also fadded



  • @munsterlander Nothing here man i’ll check my plugins



  • @Leonardo-Augusto Whats not working? The checking of internet connection? Was it working before? I don’t have these plugins installed, but I can do it real quick to test something. I just reworked your code and it should function, but errors, you know! I might have missed something as I just typed it without testing. :bowtie:


  • Onsen UI

    That’s interesting, looks like script tag makes that effect.

    @Leonardo-Augusto If you are using beta.7 you can use promises for ons.notification. I think it’s much easier.



  • @munsterlander checking internet



  • @Fran-Diox Yes it’s easy ! Onsen is cool . I guess my problem was here: index==0
    But now , I found a problem with my code to check internet. Lol. i can’t to write my .js lol but i have made effects here



  • @Leonardo-Augusto After actually reading the docs (HA!), I saw what the issue is. I have updated the code last posted. Try it now.

    https://cordova.apache.org/docs/en/latest/cordova-plugin-network-information/index.html



  • @Fran-Diox You are right. That pesky script tag was causing the issues. I removed it in my code and BOOM! The code is bright! So bright you say, yes, so I bright I have to wear shades! :sunglasses:



  • @munsterlander ahahaha do you have a class to teach me?

    <script src="angular-onsenui.js"></script>
       <script>
           document.addEventListener("deviceready", onDeviceReady, false);
    
           function onDeviceReady() {
               checkConnection();
           }
       
           function checkConnection() {
    
               var networkState = navigator.connection.type;
    
               var states = {};
               states[Connection.NONE] = 'No network connection';
                
               if (states[networkState] == 'No network connection') {
                   ons.notification.confirm({
                       message: 'Do you want to change your settings?',
                       title: 'No internet connection available',
                       buttonLabels: ['Yes', 'No'],
                       animation: 'none',
                       primaryButtonIndex: 1,
                       cancelable: false,
                       callback: function (index) {
                           if (index == 0) {
                               if (typeof cordova.plugins.settings.openSetting != undefined) {
                                   cordova.plugins.settings.openSetting("wifi", function () { console.log("Open the settings") }, function () { console.log("error to acess") });
                               }
                           } else if (index == 1) {
                               navigator.app.exitApp();
                           }
                       }
                       });
               }
               }
           
    
        </script>
    

    Reputation 13. Yes i’m not good lol But you saved my code!



  • @Leonardo-Augusto Glad it is working!



  • This post is deleted!


  • @munsterlander thanks again.



  • @munsterlander looking to your code modifications i agree that isn’t necessary
    to keep part of the code like:

    states[Connection.WIFI] = 'WiFi connection';
                states[Connection.CELL_2G] = 'Cell 2G connection';
                states[Connection.CELL_3G] = 'Cell 3G connection';
                states[Connection.CELL_4G] = 'Cell 4G connection';
                states[Connection.CELL] = 'Cell generic connection';
    

    When i’m checking just my connection ( If i have or not)
    I just have added other navigator.app.exitApp(); for one reason:
    if the user access the settings but cancel for any reason , could be possible to return to the application.

     if (index == 0) {
                               if (typeof cordova.plugins.settings.openSetting != undefined) {
                                   cordova.plugins.settings.openSetting("wifi", function () { console.log("Acessando suas configurações") }, function () { console.log("Erro para alterar configurações, tente manualmente!") });
                               }
                           } else if (index == 1) {
                               navigator.app.exitApp();
                           }
                           navigator.app.exitApp();