我希望在从firebase收到它后,由NSLog在viewController中看到fireINotification的instanceId

时间:2017-03-28 12:12:51

标签: ios objective-c devicetoken

我可以在AppDelegate.m上获取Firebase通知的instanceId 应用程序加载后需要几秒钟才能获得它。 我想将它存储到我的服务器但我不能将它发送到我的服务器。 这就是为什么我不能单独发送推送通知。 所以,请问我该怎么做,以下是我的代码。

//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];
}

我想在第一次用户安装我的应用程序时将refreshToken存储到我的服务器。请帮我。我现在疯了。

0 个答案:

没有答案