Search code examples
ioscordovaweb-applicationsnotificationsconfirm

Phonegap Only 1 buttonIndex is working in Notification.confirm


I'm using the Phonegap 'confirm' in iOS.

When to use 'confirm', two buttons shown, but to be working only 1 button.

[Yes, No] button.

if the 'Yes' button is pressed only 'callback' function is activated and

'No' button nothing happens..

What should I do?

My Code>>

video.addEventlistener("ended",function(){
    console.log('onended');
    navigator.notification.confirm(
        'Exit?',
        onConfirm,
        'Done',
        ['Yes','No']
    );
}, false);

function onConfirm(button){
    console.log(button);
    if(button == 1){
        location.href = history.go(-1);
    }else if(button == 2){
        ...
    }
}

if I clicked Yes button, log displayed 1.

if I clicked No button, log not displayed nothing.

Phonegap 2.9.1 version

I had to use 'string' on button name. but deprecated happens. solved to use 'array'


Solution

  • Try

     function onConfirm(buttonIndex) {
            alert('You selected button ' + buttonIndex);
        }
    

    This way, try getting index of both button (Yes and No) and accordingly you can define your conditional logic.