davide-scalzo / react-native-mixpanel

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

Push Notification on iOS #182

Closed YahiaJabeur closed 5 years ago

YahiaJabeur commented 5 years ago

Hiiiii, I integrated the react-native-mixpanel library to my project. RN 59.5

I followed all steps in the iOS official documentation

Should I add this code to AppDelegate.m ???? `- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {

// Initialize Mixpanel with your project token
[Mixpanel sharedInstanceWithToken:@"YOUR PROJECT TOKEN"];
Mixpanel *mixpanel = [Mixpanel sharedInstance];

// Tell iOS you want your app to receive push notifications
// This code will work in iOS 8.0 xcode 6.0 or later:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
// This code will work in iOS 7.0 and below:
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}

// Call .identify to flush the People record to Mixpanel
[mixpanel identify:mixpanel.distinctId];

return YES;

}`

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

And can someone plz confirm me if I need to send the device token id to mixpanel ` import DeviceInfo from 'react-native-device-info';

  const deviceId = DeviceInfo.getDeviceId();
    Mixpanel.identify(deviceId);
    Mixpanel.set({ $ios_devices: deviceId });
    if (Platform.OS === 'ios') Mixpanel.addPushDeviceToken(deviceId);

one more question, is it ok I useAutomatically manage siging` to test on my real device dev mode???

YahiaJabeur commented 5 years ago

resolved. solution : this piece of code should be added at the end of the file AppDelegate.m

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

abeddow91 commented 4 years ago

Hi Yahia,

I'm also having this problem. Did you add all the above to your AppDelegate.m ?

Thanks, Anna

YahiaJabeur commented 4 years ago

@abeddow91 Yes, please make sure to add it at the end of the file