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.
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
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