0

I am using ionic 6 project and installed one signal plugin for notification.

$ ionic cordova plugin add onesignal-cordova-plugin 
$ npm install @awesome-cordova-plugins/onesignal 

Plugin version in my package.json. "onesignal-cordova-plugin": "^3.1.0", "@awesome-cordova-plugins/onesignal": "^5.44.0",

Android Platform version *** android 10.0.0 *** After Implementing, made build by ionic cordova build android / by --prod and installed it. After opening the installed application its throw error of

ERROR Error: Uncaught (in promise): plugin_not_installed

[ERROR Error: Uncaught (in promise): plugin_not_installed ][2] [2]: https://i.stack.imgur.com/zUBxy.png

vendor.js:82382 ERROR Error: Uncaught (in promise): plugin_not_installed
    at resolvePromise (polyfills.js:1364:35)
    at polyfills.js:1271:21
    at rejected (vendor.js:42934:89)
    at push.3484._ZoneDelegate.invoke (polyfills.js:511:30)
    at Object.onInvoke (vendor.js:101445:33)
    at push.3484._ZoneDelegate.invoke (polyfills.js:510:56)
    at push.3484.Zone.run (polyfills.js:271:47)
    at polyfills.js:1428:38
    at push.3484._ZoneDelegate.invokeTask (polyfills.js:545:35)
    at Object.onInvokeTask (vendor.js:101432:33)

I have tired installing all versions: 5.36.0,5.36.1,5.37.0 etc from https://www.npmjs.com/package/@awesome-cordova-plugins/onesignal/v/5.37.0 but still facing the same issue.

Package.json file

{
 "name": "My App",
 "version": "0.0.1",
 "author": "Ionic Framework",
 "homepage": "https://ionicframework.com/",
 "scripts": {
   "ng": "ng",
   "start": "ng serve",
   "build": "ng build",
   "test": "ng test",
   "lint": "ng lint",
   "e2e": "ng e2e"
 },
 "private": true,
 "dependencies": {
   "@angular/common": "~13.2.2",
   "@angular/core": "~13.2.2",
   "@angular/forms": "~13.2.2",
   "@angular/platform-browser": "~13.2.2",
   "@angular/platform-browser-dynamic": "~13.2.2",
   "@angular/router": "~13.2.2",
   "@awesome-cordova-plugins/core": "^5.43.0",
   "@awesome-cordova-plugins/onesignal": "^5.44.0",
   "@awesome-cordova-plugins/status-bar": "^5.43.0",
   "@capacitor/app": "1.1.1",
   "@capacitor/haptics": "1.1.4",
   "@capacitor/keyboard": "1.2.2",
   "@capacitor/status-bar": "1.0.8",
   "@ionic-native/core": "^5.36.0",
   "@ionic/angular": "^6.0.0",
   "@ionic/cordova-builders": "^6.1.0",
   "@ionic/storage": "^2.2.0",
   "com.razorpay.cordova": "1.4.14",
   "cordova-plugin-device": "^2.0.2",
   "cordova-plugin-ionic-keyboard": "^2.2.0",
   "cordova-plugin-ionic-webview": "^5.0.0",
   "cordova-plugin-splashscreen": "^5.0.2",
   "cordova-plugin-statusbar": "^2.4.2",
   "rxjs": "~6.6.0",
   "tslib": "^2.2.0",
   "zone.js": "~0.11.4"
 },
 "devDependencies": {
   "@angular-devkit/build-angular": "~13.2.3",
   "@angular-eslint/builder": "~13.0.1",
   "@angular-eslint/eslint-plugin": "~13.0.1",
   "@angular-eslint/eslint-plugin-template": "~13.0.1",
   "@angular-eslint/template-parser": "~13.0.1",
   "@angular/cli": "~13.2.3",
   "@angular/compiler": "~13.2.2",
   "@angular/compiler-cli": "~13.2.2",
   "@angular/language-service": "~13.2.2",
   "@ionic/angular-toolkit": "^6.0.0",
   "@types/jasmine": "~3.6.0",
   "@types/jasminewd2": "~2.0.3",
   "@types/node": "^12.11.1",
   "@typescript-eslint/eslint-plugin": "5.3.0",
   "@typescript-eslint/parser": "5.3.0",
   "cordova-android": "^10.0.0",
   "cordova-browser": "^6.0.0",
   "cordova-sqlite-storage": "^6.0.0",
   "eslint": "^7.6.0",
   "eslint-plugin-import": "2.22.1",
   "eslint-plugin-jsdoc": "30.7.6",
   "eslint-plugin-prefer-arrow": "1.2.2",
   "jasmine-core": "~3.8.0",
   "jasmine-spec-reporter": "~5.0.0",
   "karma": "~6.3.2",
   "karma-chrome-launcher": "~3.1.0",
   "karma-coverage": "~2.0.3",
   "karma-coverage-istanbul-reporter": "~3.0.2",
   "karma-jasmine": "~4.0.0",
   "karma-jasmine-html-reporter": "^1.5.0",
   "onesignal-cordova-plugin": "^3.1.0",
   "protractor": "~7.0.0",
   "ts-node": "~8.3.0",
   "typescript": "~4.4.4"
 },
 "description": "An Ionic project",
 "cordova": {
   "plugins": {
     "cordova-plugin-statusbar": {},
     "cordova-plugin-device": {},
     "cordova-plugin-splashscreen": {},
     "cordova-plugin-ionic-webview": {},
     "cordova-plugin-ionic-keyboard": {},
     "cordova-sqlite-storage": {},
     "onesignal-cordova-plugin": {},
     "com.razorpay.cordova": {}
   },
   "platforms": [
     "browser",
     "android"
   ]
 }
}

called onesingal function after platform ready in > app.component.ts .

constructor(private navCtrl: NavController, private platform: Platform,
    private statusBar: StatusBar, public oneSignal: OnesignalService) {
   this.appInitialize();
 }

 appInitialize() {
   this.platform.ready().then(() => {
     this.statusBar.backgroundColorByHexString('#ff6657');
     this.oneSignal.OneSignalNotification();
   });
 }

Please guide , if anyone faced this issue and resolved it.

AziDev
  • 11
  • 5

1 Answers1

0

For Capacitor:

import OneSignal from 'onesignal-cordova-plugin';



async OneSignalInit() {
    OneSignal.setAppId(this.ONESIGNAL_APP_ID);

    OneSignal.setNotificationOpenedHandler((jsonData) => {
      console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
    });

    OneSignal.promptForPushNotificationsWithUserResponse((accepted) => {
      console.log('User accepted notifications: ' + accepted);
    });
  }
Mostafa Harb
  • 1,558
  • 1
  • 6
  • 12
  • I haven't used capacitor. Do you have any solution without using capacitor? – AziDev Sep 14 '22 at 09:19
  • @AziDev this one work even for ionic 3, so it should work without Capacitor – WatsMyName Feb 10 '23 at 08:29
  • @WatsMyName Agreed! But the thing is it shows "ERROR Error: Uncaught (in promise): plugin_not_installed". If this error will solved then i can check this initialisation code. But i am stuck to resolve this error. – AziDev Feb 13 '23 at 06:37
  • @AziDev , did u do the installs? `npm install onesignal-cordova-plugin` then run the command `ionic cap sync`.. reference: `https://ionicframework.com/docs/v5/native/onesignal` ... just be aware the code there will not work as i thin its a bit out dated or at least isn't working at some point.. use the code mentioned above... – Mostafa Harb Feb 13 '23 at 08:58
  • @AziDev, I tested with this code, in my ionic 2 application. It worked, we don't need ionic's native onesignal wrapper. – WatsMyName Feb 13 '23 at 09:19
  • @MostafaHarb yes, if i'll use lower version plugin like **ionic v5 "npm install onesignal-cordova-plugin"** , Then it will work but as i installed new version plugin **ionic v6 "npm install @awesome-cordova-plugins/onesignal"** then it will stop working it will show **"Plugin Not Installed"** error even if plugin is installed properly and my project is of ionic 6. – AziDev Feb 22 '23 at 10:29
  • @WatsMyName Yes it will work, because you checked in ionic V2 application, I facing issue in IonicV6 application with ionic V6 onesignal plugin – AziDev Feb 22 '23 at 10:31
  • @AziDev , i haven't used ionic 6 yet.. but even in ionic 5, when i used to install `npm install @awesome-cordova-plugins/onesignal`, it seems to start giving error... so i only install `npm install onesignal-cordova-plugin` and do npx cap sync and then it could work with the code above.. – Mostafa Harb Feb 23 '23 at 12:40
  • @MostafaHarb. Hence, i am already using `npm install @awesome-cordova-plugins/onesignal` in V6 and its throwing me error. So, you mean to say i should run `npx cap sync` ? – AziDev Mar 07 '23 at 06:58