Angular Cordova Firebase Token

Viewed 64

I Got an problem with get my token in firebase in my angular project that converted to android and iOS by Cordova Please I need help in this and the event not launched at all My Angular version is 8.1 Here is My code :

```
 @HostListener("document:deviceready", [])
  deviceReady() {
    
    console.log('DeviceID',this.uuid);

    

    this.user.DeviceID = this.uuid;

    (window as any).cordova.plugins.firebase.messaging.onMessage((payload) => {
      console.log('Angular New foreground FCM message: ', payload);
      try {

        window.alert('You have a new notificaion');
 
      }
      catch (Exception) { console.log("error",Exception.message); }

    });

    (window as any).cordova.plugins.firebase.messaging.onBackgroundMessage((payload) => {
      console.log('Angular  New background FCM message: ', payload);
    });

    

    (window as any).cordova.plugins.firebase.messaging.requestPermission().then(() => {
      (window as any).cordova.plugins.firebase.messaging.getToken().then((token) => {
        console.log('Angular  Got device token: ', token);
        this.user.userToken = token;
        console.log('Token = :' + token);
        
      });
    });


      return true;
  }


  
  @HostListener('window:popstate', ['$event'])
  onPopState(event) {

    //alert(this.currentUrl +"---" + this.previousUrl);
    //this.router.navigate(['./'+this.currentUrl]);

    (window as any).navigator.Backbutton.goHome(function () {
      this.router.navigate(['./mainpage/News']);
    }, function () {

    });
    (window as any).navigator.Backbutton.goBack(function () {
      this.router.navigate(['./mainpage/News']);
    }, function () {

    });

  }

And when I call function on constructor I got that error:

Uncaught TypeError: Cannot redefine property: BetterJsPop
    at Function.defineProperty [as __zone_symbol__defineProperty] (<anonymous>)
    at inject (<anonymous>:5:1137)
    at <anonymous>:6:9
    at <anonymous>:7:9

and here is my package.json :

{
  "name": "rayatradecommunication",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.14",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "~8.2.11",
    "@angular/compiler": "~8.2.11",
    "@angular/core": "~8.2.11",
    "@angular/fire": "^5.4.2",
    "@angular/forms": "~8.2.11",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.2.11",
    "@angular/platform-browser-dynamic": "~8.2.11",
    "@angular/router": "~8.2.11",
    "@firebase/messaging": "^0.9.4",
    "@ionic-native/unique-device-id": "^5.23.0",
    "basic-ftp": "^4.5.4",
    "bootstrap": "^4.4.1",
    "device-uuid": "^1.0.4",
    "firebase": "^7.24.0",
    "ftp": "^0.3.10",
    "ftp-client": "^0.2.2",
    "hammerjs": "^2.0.8",
    "json-server": "^0.15.1",
    "ngx-bootstrap-navbar": "0.0.4",
    "ngx-device-detector": "^1.4.1",
    "promise-ftp": "^1.3.5",
    "rxjs": "~6.4.0",
    "tslib": "^1.11.1",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "<0.900 || ^0.900.0-0 || ^9.0.0-0",
    "@angular-devkit/build-angular": "^0.803.25",
    "@angular/cli": "^8.3.25",
    "@angular/compiler-cli": "~8.2.11",
    "@angular/language-service": "~8.2.11",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.2.1",
    "firebase-tools": "^7.12.0",
    "ftp-deploy": "^2.3.6",
    "fuzzy": "^0.1.3",
    "inquirer": "^6.2.2",
    "inquirer-autocomplete-prompt": "^1.0.1",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "protractor": "^5.4.3",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  },
  "browser": {
    "fs": false,
    "path": false,
    "os": false,
    "crypto": false,
    "stream": false,
    "http": false,
    "tls": false,
    "zlib": false,
    "https": false,
    "net": false
  }
}
0 Answers
Related