question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: PushNotifications registration & registrationError listeners not fired

See original GitHub issue

Bug Report

Capacitor Version

npx cap doctor output:

Installed Dependencies: @capacitor/cli 1.4.0 @capacitor/core 1.4.0 @capacitor/ios 1.4.0 @capacitor/android 1.4.0 [success] Android looking great! 👌 Found 0 Capacitor plugins for ios: success] iOS looking great! 👌

Affected Platform(s)

  • iOS
  • Android
  • Electron
  • Web

Current Behavior

First I remove the app and on start up, the “permission alert” appears asking for notification permissions. Whether I accept or decline, no listener is fired on my real iOS device (iPhone Xs 13.1.3). However, when testing using the iOS Simulator, the registrationError listener is indeed fired.

When I click on the “permission alert”, this is printed in the console:

APP ACTIVE ⚡️ TO JS {“isActive”:true} ⚡️ [log] - onAppStateChange {“isActive”:true}

So for some reason, this listener is fired instead.

Expected Behavior

PushNotifications listeners should fire after accepting/declining permissions.

Sample Code or Sample Application Repo

I am using Ionic + Vue.js.

    PushNotifications.register();

    PushNotifications.addListener('registration', token => {
      console.log('Push registration success, token: ' + token.value);
    });

    PushNotifications.addListener('registrationError', error => {
      console.log('Error on registration: ' + JSON.stringify(error));
    });

    PushNotifications.addListener('pushNotificationReceived', notification => {
      console.log('Push received: ' + JSON.stringify(notification));
    });

    PushNotifications.addListener('pushNotificationActionPerformed', notification => {
      console.log('Push action performed: ' + JSON.stringify(notification));
    });

Other Technical Details

npm --version output: 6.13.0

node --version output: v12.9.1

pod --version output (iOS issues only): 1.8.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lfa-vasconcelloscommented, Dec 13, 2019

@bryplano Yes, you are correct. I added print() to debug what was going on in PushNotifications.swift and suddenly it worked. Does Xcode cache certain files on build? Anyway, it works now. Thanks.

Had this exact problem, even after reinstalling packages. Writing to the file solved it. Thanks!

1reaction
bryplanocommented, Dec 13, 2019

I would wager it is related to this PR (the doc update came out in 1.4.0 and there was a small code change or two around the push code on iOS): https://github.com/ionic-team/capacitor/pull/2078

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capacitor PushNotifications registration and registrationError ...
I implemented push notifications using Firebase FCM, Ionic V4 and Capacitor. I built the app for both Android and iOS. Everything is working...
Read more >
"push Notification Action Performed" listener not triggered all ...
Sometimes the “pushNotificationActionPerformed” listener it's not triggered. When application it's closed, after we tap on a notification, ...
Read more >
Troubleshooting Push with Capacitor - Ionic
This guide walks through the process of registering and receiving Push Notifications with a Capacitor application, defines success criteria ...
Read more >
Firebase Push Notification in Ionic React app using Capacitor
Learn how to implement firebase push notifications in Ionic-React apps using Capacitor ... This listener will fire when your registration is not successful....
Read more >
How to use the react-native-push-notification.configure ... - Snyk
addEventListener('registrationError', error => console.warn(error) ) } PushNotification.configure({ // Called when Token is generated (iOS and Android) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found