0

I am using cordova 6.0.0 and cordova-platform-android 6.0.0 for developing my ionic app. I have added the one signal plugin in initialization scripts. The script looks like below.

sudo cordova platform add ios
sudo cordova platform add android
sudo ionic resources

sudo cordova plugin add onesignal-cordova-plugin
sudo cordova plugin add cordova-plugin-crosswalk-webview
sudo cordova plugin add ionic-plugin-keyboard
sudo cordova plugin add cordova-plugin-whitelist
sudo cordova plugin add cordova-plugin-console
sudo cordova plugin add cordova-plugin-splashscreen
sudo cordova plugin add cordova-plugin-network-information
sudo cordova plugin add cordova-plugin-screen-orientation
sudo cordova plugin add cordova-plugin-inappbrowser
sudo cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
sudo cordova plugin add cordova-plugin-vibration
sudo cordova plugin add https://github.com/VersoSolutions/CordovaClipboard.git

In my ionic app in the app.js file I called the OneSignal init method as below.

ionic.Platform.ready(function () {
    app.run(function () {

        var notificationOpenedCallback = function(jsonData) {
            //console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
        };
        console.log('oneSignal plugin', window.cordova.plugins.OneSignal);
        window.cordova.plugins.OneSignal.init("my-one-signal-app-id",
            {googleProjectNumber: "my-google-app-id"},
            notificationOpenedCallback);

        window.cordova.plugins.OneSignal.enableInAppAlertNotification(true);


    });
});

But when I run the app it displays as below

oneSignal plugin undefined
app.js:29 Uncaught TypeError: Cannot read property 'init' of undefined

Is it an issue with cordova 6.0.0 or I have done any wrong with the approach?

4

1 回答 1

0

我发现了 2 个错误。1. 而不是使用 window.cordova.plugins 我必须使用 window.plugins 2. 在我的应用程序中,服务会覆盖插件。所以它显示 OneSignal 未定义。它适用于科尔多瓦 6.0.0 和科尔多瓦平台 android 6.0.0。

于 2016-02-12T01:54:55.870 回答