Search code examples
androidangularjsmobile-applicationphonegap

How to display logout alert box in ios mobile application


I am running this using phonegap. When i run in Android the logout box is correct and its showing "confirm" as title in the logout box. Even in ios everything is perfect but the logout box shows title as "index.html"(which is the current page name)

                         $rootScope.logout=function()
                        {

                  response=confirm(GetLocalString("HMLOGOUTMSG",_language));
                            if(response==true)
                            {
                                logout();
                            }
                            else
                            {
                                menuchk();
                            }
                        }

I dont want the title as "index.html". Can you suggest a method to not display the title as "index.html"


Solution

  • In ios PhoneGap pages will show the page name in alert, you need to use a plugin for notification. To add the plugin run this code.

    cordova plugin add cordova-plugin-dialogs
    

    Usage

    navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
    
    • message: Dialog message. (String)
    • confirmCallback: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). (Function)
    • title: Dialog title. (String) (Optional, defaults to Confirm)
    • buttonLabels: Array of strings specifying button labels. (Array) (Optional, defaults to [OK,Cancel])

    Example

    function onConfirm(buttonIndex) {
        alert('You selected button ' + buttonIndex);
    }
    
    navigator.notification.confirm(
        'You are the winner!', // message
         onConfirm,            // callback to invoke with index of button pressed
        'Game Over',           // title
        ['Restart','Exit']     // buttonLabels
    );
    

    The callback takes the argument buttonIndex (Number), which is the index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.

    Documentation

    Now its working fine,

    $rootScope.logout = function () {
        function onConfirm(buttonIndex) {
            if (buttonIndex == 1) {
                logoutfunc();
            }
            else {
                menuopenchk();
            }
        }
    
        navigator.notification.confirm(
            'Are you sure to logout?',
            onConfirm,
            'Logout',
            ['Yes', 'Not Now']
        );
    }