Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Has anyone managed to get iOS push notifications working with @react-native-firebase/messaging 6.7.1? #234

Closed
SMJ93 opened this issue May 15, 2020 · 5 comments

Comments

@SMJ93
Copy link

SMJ93 commented May 15, 2020

It used to work fine with firebase v5, but since upgrading I don't receive any notifications.

Here is my code:

JS:

    const pushToken = await messaging().getToken();
    Mixpanel.addPushDeviceToken(pushToken);
    Mixpanel.identify(userId);

AppDelegate.m

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  Mixpanel *mixpanel = [Mixpanel sharedInstance];
  [mixpanel.people addPushDeviceToken:deviceToken];
}
@0hio-creator
Copy link

Hey,

I'm using the following to register the token with mixpanel.

for ios

let token = await messaging().getAPNSToken()
            Mixpanel.addPushDeviceToken(token)

Not using any native code

  • request permissions
 const authStatus = await messaging().requestPermission();

Using firebase messaging to handle responese

export const backgroundHandler = async () => {
    messaging().setBackgroundMessageHandler(async remoteMessage => {
        console.log('Message handled in the background!', remoteMessage);
    });
} 

@SMJ93
Copy link
Author

SMJ93 commented May 27, 2020

Hi @0hio-creator, what about calling addPushDeviceToken in the AppDelegate.m?

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  Mixpanel *mixpanel = [Mixpanel sharedInstance];
  [mixpanel.people addPushDeviceToken:deviceToken];
}

Don't you need to do this?

@0hio-creator
Copy link

@SMJ93
Mixpanel.addPushDeviceToken(token) does the same thing but slightly different usage.

The delegate sets a callback to send the apns token whenever didRegisterForRemoteNotificationsWithDeviceToken is called.

Where as Mixpanel.addPushDeviceToken(token) is called where you choose to run it.

messaging().requestPermission() Is the firebase call for registering for remote notifications. So i did ~something like this

var authStatus = await messaging().requestPermission()
// check user has given permission
if (authStatus == 1 || authStatus ==2) {
      let token = await messaging().getAPNSToken()
      Mixpanel.addPushDeviceToken(token)
}

After i register for notifications.

Another thing to note is that you need to have called Mixpanel.identify somewhere before either Mixpanel.addPushDeviceToken or the delegate.m code is called.
Particularly watch for the case of an app reinstall

@SMJ93
Copy link
Author

SMJ93 commented May 28, 2020

Thanks @0hio-creator !

@roni-castro
Copy link

roni-castro commented Jun 9, 2020

Have anyone had problem on receiving mixpanel push notification on Foreground (app is visible to the user) using the react-native-firebase?
Currently I am not able to receive it on foreground (on iOS), but I receive it on background and I did not add any Mixpanel native configuration and I am calling the Mixpanel.identify and sending the APN token through Mixpanel.addPushDeviceToken(token)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants