davide-scalzo / react-native-mixpanel

A React Native wrapper for Mixpanel tracking
MIT License
455 stars 195 forks source link

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

Closed SMJ93 closed 4 years ago

SMJ93 commented 4 years ago

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 commented 4 years ago

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

Using firebase messaging to handle responese

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

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 commented 4 years ago

@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 commented 4 years ago

Thanks @0hio-creator !

roni-castro commented 4 years ago

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)