[英]Phonegap navigator.notification.alert callback is not working with cordova2.1.0 for Android
我正在使用 cordova2.1.0 開發一個 android 應用程序,在此我使用 navigator.notification.alert 並在單擊警報的“確定”按鈕時使用回調 function。 我收到彈出警報,但在單擊“確定”時未調用回調 function。 我使用 cordova2.0.0 版本讓它工作,但在 cordova2.1.0 中不工作。 請幫我。 我使用的代碼如下:
function WriteReviewAlert(){
navigator.notification.alert(
'Alert message.', // message
gotoSettings, // callback
'Test', //title
'OK' // buttonName
);
}
function gotoSettings()
{
$.mobile.changePage( 'settings.html', { transition: "slide"} );
}
選中它可能對您有幫助。
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
function onDeviceReady() {
}
function onConfirm(button) {
alert('...');
}
function showConfirm() {
navigator.notification.confirm(
'You are the best!', // message
onConfirm, // callback to invoke with index of button pressed
'TEST', // title
'OK' // buttonLabels
);
}
</script>
</head>
<body>
<p><a href="#" onclick="showConfirm(); return false;">Show Confirm</a></p>
</body>
</html>
我的項目更好地將頁面更改從確認回調中取出,因此它們是分開的。 像這樣:
async showConfirm(): Promise<void> {
await new Promise<void>((resolve: any, reject: any) => {
navigator.notification.confirm(
'You are the best!', // message
// callback to invoke with index of button pressed
(btnId: number) => {
if (btnId === 1) {
resolve();
} else {
reject();
},
},
'TEST', // title
'OK' // buttonLabels
);
}).then(() => {// Needed because we are navigating
gotoSettings():
}).catch(() => {
// Silent
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.