0
我在webview中將現有的Web應用程序(Rails)作爲cordova app
包裝。我打開onDeviceReady的主頁。隨後註冊推送通知。Phonegap - 使用嵌入式Web應用程序推送通知(InAppBrowser窗口)
var ref = cordova.InAppBrowser.open(window.app_url,
'_blank', 'location=no,clearsessioncache=no');
setupPushNotifications(window.app_url, ref);
我正在使用phonegap-plugin-push
進行推送通知。
push.on('registration', function(data) {
saveRegistrationId(app_url, data);
});
我想在Web應用程序中登錄用戶的上下文中關聯通知registrationId。
這似乎在使用phonegap開發人員應用程序時沒有困難。但是,當我在我的設備上安裝android-debug.apk
時,這不會打電話給rails應用程序以保存registrationId。
config.xml中
<access origin="*" />
<allow-navigation href="http://192.168.1.3:8000" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
的內容我還試圖_self
,在同一個web視圖中打開。它不運行setupPushNotifications。
用於登記令牌
function saveRegistrationId(app_url, data) {
// this is our payload for the POST request to server
// data = {registrationId: 'XXXXX', registrationType: 'FCM'}
const device_data = Object.assign(data, this.device);
const url = app_url + "/mobile_devices";
navigator.notification.alert(data.registrationId);
navigator.notification.alert(url);
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', url);
httpRequest.onreadystatechange = function() {
navigator.notification.alert('readyState : ' + httpRequest.readyState);
navigator.notification.alert('status : ' + httpRequest.status);
if (httpRequest.readyState>3 && httpRequest.status==200) { console.log(httpRequest.responseText); }
};
httpRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
httpRequest.setRequestHeader('Content-Type', 'application/json');
httpRequest.send(JSON.stringify({device: device_data}));
}
你配置了你的'cordova-plugin-whitelist'嗎?在實際設備上運行時,請嘗試使用Chrome開發人員工具來檢查應用程序是否存在JS /網絡錯誤。 – wildabeast
我已經用config.xml文件中的設置更新了問題。 – naruvimama
您是否在Javascript控制檯中看到任何JS錯誤/網絡錯誤? – wildabeast