I have an Ionic project running. Its at that point where its gotten quite large and every now and then I get some plugin issues where uninstalling and reinstalling them fixes the issue, however Ionic Native OneSignal has given me the biggest problems. It runs perfectly on all iOS devices (up to v 11.4.1), but on android (tested on android 9 and android 8.1.0) I get a plugin not installed error.
I have followed the standard approach to adding one signal to the project:
$ ionic cordova plugin add onesignal-cordova-plugin
$ npm install --save @ionic-native/onesignal
It seems that after narrowing it down to when exactly the error gets thrown its by the methods
this.oneSignal.handleNotificationReceived().subscribe(data => {});
this.oneSignal.handleNotificationOpened().subscribe(data => {});
Init seems to be called successfully. So does inFocusDisplaying.
Obviously these are very important methods for successfully using OneSignal. Im not sure why they would work with iOS but fail on android.
This has completely halted our releases and moving forward with other development. Because this code takes place before the root is set, it fails and the root never gets set. We can obviously move things around or pull it out to make the app functional but thats not how we want to solve this problem.
Any help would be greatly appreciated. Let me know if you need more info.
Info
app.component
constructor(private oneSignal: OneSignal){
this.platform.ready().then(() => {
this.initializePluginValues();
});
}
public initializePluginValues(): void {
if (this.platform.is('cordova')) {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
this.keyboard.hideKeyboardAccessoryBar(false);
this.splashScreen.hide();
this.initializeOneSignal();
}
}
public initializeOneSignal(): void {
this.oneSignal.startInit(oneSignalAppId, oneSignalSenderId);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.None);
this.handleNotifications();
this.oneSignal.endInit();
}
//This is whats failing!! Both methods fail individually as well as together
private handleNotifications(): void {
this.oneSignal.handleNotificationReceived().subscribe(data => {
});
this.oneSignal.handleNotificationOpened().subscribe(data => {
});
}
config.xml
<plugin name="onesignal-cordova-plugin" spec="^2.4.3" />
package.json
dependencies: {
“@ionic-native/onesignal”:"^4.12.2",
“onesignal-cordova-plugin”:"^2.4.3",
}
plugins: {
“onesignal-cordova-plugin”: {}
}
versions
Ionic:
ionic (Ionic CLI) : 4.0.0 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.1.9
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
System:
ios-deploy : 1.9.2
NodeJS : v8.11.1 (/usr/local/bin/node)
npm : 6.3.0
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Environment:
ANDROID_HOME : not set