Ionic One信号插件未安装在ionic 6 android平台10.0.0问题中

fumotvh3  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(149)

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.

jjhzyzn0

jjhzyzn01#

对于电容器:

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);
    });
  }

相关问题