[RC4] Unable to register device token for push notification

I’m using Ionic RC4 ith cloud service, this is my code which reference from doc: https://docs.ionic.io/services/push/

(The phonegap-plugin-push has installed)

platform.ready().then(() => {
  StatusBar.styleDefault();
  Splashscreen.hide();

  this.push.register().then((t: PushToken) => {
    console.log('This scope will never executed.');
    return this.push.saveToken(t, {ignore_user: true});
  }).then((t: PushToken) => {
    alert(t.token); // I add an alert to check token registered, but also not executed.
    console.log('Token saved:', t.token);
  });

  this.push.rx.notification()
    .subscribe((msg) => {
      alert(msg.title + ': ' + msg.text);
    });
});

I added an alert to check the token registered or not, but I always unable to get any response of push.register(), the code in then() didn’t executed without any error messages or console logs.

I tried in browser, Ionic View and iOS simulator, they are all no works. Also, I add a push notification from apps.ionic.io but it still can not receive any notifications.

Any one have ideas?

Push notifications only work on a true device, they do not work in the browser, the simulators, or Ion View (on the device). You must run your app natively on a device to register for push.

Thank you.

So if I want to test push notifications in iOS, It is impossible before I publish my app to apple app store?

Is there any way to test or mock the push notification that I can finish my app features. Is it possible to compile an ios app to Xcode simulator to test push notifications like this article said: https://mobiforge.com/design-development/programming-apple-push-notification-services?

Or I need to prepare an Android device to test?

You can use a process called side loading, to install your IOS application to an iPhone, iPad or AppleTV before it reaches the app store, it involves using Xcode and debugging your app while it’s tethered to your laptop (if you have mac).

You can complete the same process for android, though it’s a bit easier and can be done from the command line using
ionic run android --device
while it’s tethered to the laptop, and debug mode is enabled on the device.

1 Like

OK, I see. Thank you.