Push Notification on iOS
Closed this issue · 3 comments
Hiiiii,
I integrated the react-native-mixpanel library to my project. RN 59.5
- Track event work fine for Android and iOS
- Push notification works on android but not on iOS
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 use
Automatically manage siging` to test on my real device dev mode???
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]; }
Hi Yahia,
I'm also having this problem. Did you add all the above to your AppDelegate.m ?
Thanks,
Anna
@abeddow91
Yes, please make sure to add it at the end of the file