Error: Error Subscribing for Push Notifications

Hi,

I’ve followed the steps provided in the Ionic documentation to enable push notifications on my app - everything seems to work fine (I can even send notifications to my iOS device from within the ionic dashboard). However what’s really bugging is it doesn’t seem the register promise is working.

I’m trying to store the device token on my server & assign that token to my users. Unfortunately everything inside my promise doesn’t run:

this.attachDeviceToken() simply sends the token via HTTP to my server.

this.push.register().then((t: PushToken) => {
      this.device_token = t.token;
      this.attachDeviceToken();
      return this.push.saveToken(t);
    });

I’ve also tried it this way:

this.push.register().then((t: PushToken) => {
  return this.push.saveToken(t);
}).then((t: PushToken) => {
  this.device_token = t.token;
  this.attachDeviceToken();
});

The above code is currently running inside a custom authorisation provider.

When running in browser, I get this error:

core.es5.js:1084 ERROR Error: Uncaught (in promise): Error: Error subscribing for Push notifications.
Error: Error subscribing for Push notifications.

I’ve tried removing the platforms/plugin and re-adding to no avail. It would seem that even when testing on a physical device, attachDeviceToken() never gets to run. Has anyone had a similar issue or does anyone know of anything I could do to try and fix it?

Thanks

please paste the entire class
i need more informations before tell what i am thinking about.

Hey @bradbeatson could you tell me how you figured out to fix this error ? I am also stuck on the same :confused:

import { Injectable, EventEmitter } from "@angular/core";
import { Http } from "@angular/http";
import { Observable, Subscription } from 'rxjs';
import 'rxjs/Rx';

import { Push, PushToken } from '@ionic/cloud-angular';

@Injectable()
export class PushService {
    pushEvent : EventEmitter<any> = new EventEmitter();
    constructor(
        public push: Push,
    ) { 
        try {
            this._initializePush();
            this._listenToPush(); 
        }
        catch(ex){
            console.error(ex);
        }  
    }

   _initializePush(){
    this.push.register().then((t: PushToken) => {
        return this.push.saveToken(t);
      }).then((t: PushToken) => {
        console.log('Token saved:', t.token);
        window.sessionStorage.setItem("token",t.token);
        console.log(window.sessionStorage.getItem("token"));
      });
   }

   _listenToPush(){
       this.push.rx.notification()
        .subscribe((msg) => {
            this.pushEvent.emit(msg);
        });
   }
}

i register the service as global, then listen to the initializesuccessevent after that i will store the token to my server.