Uncaught TypeError: Cannot read property 'OneSignal' of undefined", source: file:///android_asset/www/js/app

扶醉桌前 提交于 2019-12-07 13:08:54

问题


I'm trying to initialize OneSignal to a PhoneGap application.

I tried many ways. But always it gives following error,

Uncaught TypeError: Cannot read property 'OneSignal' of undefined", source: file:///android_asset/www/js/app.js error.

This is my app.js file

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
oneSignal();
checkConnection();}

function oneSignal(){
console.log("It is calling");
    var notificationOpenedCallback = function(jsonData) {
        console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
    };

    window.plugins.OneSignal.init("my app id",
                             {googleProjectNumber: "my project number"},
                             notificationOpenedCallback);



 // Show an alert box if a notification comes in when the user is in your app.
    window.plugins.OneSignal.enableInAppAlertNotification(true);}

Somebody please help me to initialize OneSignal to my PhoneGap application.


回答1:


The best way to initialize OneSignal is by adding the code in your controller.js file and make sure its in one of your controllers - it might be login, logout, anything.

in other words you need to add the code inside a set controller that responds to a certain action.

Cant explain it better but try that -..

Good luck




回答2:


Just try installing your plugin, cross verify for it's availability in the plugins folder. Also confirm the corresponding update has been made in config.xml and fetch.json (in the plugins folder). The error usually arises in case the plugin is not installed properly.

Hope this helps... :)



来源:https://stackoverflow.com/questions/36687064/uncaught-typeerror-cannot-read-property-onesignal-of-undefined-source-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!