0

i can get an instanceId for Firebase Notification on AppDelegate.m it takes few seconds to get it after app is already loaded. and i want to store it to my server But i can't send it to my server. that is why i can't send push Notification individually. So, Please how should do i do and following is my code.

//AppDelegate.m

#import "AppDelegate.h"
@import Firebase;
@import FirebaseMessaging;
@interface AppDelegate ()
@end
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[FIRApp configure];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
// Add an oberver for handling a token refresh callback
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(tokenRefreshCallback:)
                                             name:kFIRInstanceIDTokenRefreshNotification
                                           object:nil];

// Request permission for notifications from the user
UIUserNotificationType allNotificationTypes = (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];

//Request a device token from Apple Push Notification Services
[application registerForRemoteNotifications];

return YES;

return YES;
}

- (void)tokenRefreshCallback: (NSNotification *)notification {
NSString *refreshToken = [[FIRInstanceID instanceID] token];
NSLog(@"InstanceID token: %@", refreshToken);



[self connectToFirebase];
}

i want to store refreshToken to my server when user installed my app on first time. Please, help me. i am going crazy now.

0 Answers0