【问题标题】:Phonegap Only 1 buttonIndex is working in Notification.confirmPhonegap 只有 1 个 buttonIndex 在 Notification.confirm 中工作
【发布时间】:2014-08-30 06:00:34
【问题描述】:

我在 iOS 中使用 Phonegap 的“确认”。

何时使用“确认”,显示两个按钮,但只有一个按钮起作用。

[是,否] 按钮。

如果按下“是”按钮,则仅激活“回调”功能并且

“否”按钮没有任何反应..

我该怎么办?

我的代码>>

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){
        ...
    }
}

如果我点击是按钮,日志显示为 1。

如果我单击“否”按钮,则日志不会显示任何内容。

Phonegap 2.9.1 版本

我必须在按钮名称上使用“字符串”。 但发生了弃用。解决了使用'array'

【问题讨论】:

    标签: ios cordova web-applications notifications confirm


    【解决方案1】:

    试试

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

    这样,尝试获取两个按钮(是和否)的索引,因此您可以定义条件逻辑。

    【讨论】:

    • 天啊!它的工作!这到底是怎么发生的?代码运行后显示警报窗口!代码错了。。谢谢!!!
    【解决方案2】:

    您是在真实设备上进行测试吗?我总是无法模拟 iOS 设备,因为应用程序仅在一次交互后就停止工作。如果先按“否”会怎样?

    【讨论】:

    • 这应该是评论而不是完整答案
    • 您需要代表发表评论 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多