FCMToken在实际设备中始终为null

时间:2017-10-23 14:41:39

标签: ios firebase push-notification firebase-cloud-messaging

我正在尝试将iOS中的Fireabase通知集成5天。 但我无法在真实设备中获得fcmtoken。 它总是空的。 这是我的代码。此代码仅来自firebase GitHub示例代码。

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

[FIRApp configure];

[FIRMessaging messaging].shouldEstablishDirectChannel = true;

[FIRMessaging messaging].delegate = self;


// Register for remote notifications. This shows a permission dialog on first run, to
// show the dialog at a more appropriate time move this registration accordingly.
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
    // iOS 7.1 or earlier. Disable the deprecation warnings.
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    UIRemoteNotificationType allNotificationTypes =
    (UIRemoteNotificationTypeSound |
     UIRemoteNotificationTypeAlert |
     UIRemoteNotificationTypeBadge);
    [application registerForRemoteNotificationTypes:allNotificationTypes];
    #pragma clang diagnostic pop
} else {
    // iOS 8 or later
    // [START register_for_notifications]
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
        UIUserNotificationType allNotificationTypes =
        (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    } else {
        // iOS 10 or later
        #if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
        // For iOS 10 display notification (sent via APNS)
        [UNUserNotificationCenter currentNotificationCenter].delegate = self;
        //[FIRMessaging messaging].delegate = self;
        UNAuthorizationOptions authOptions =
        UNAuthorizationOptionAlert
        | UNAuthorizationOptionSound
        | UNAuthorizationOptionBadge;
        [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
        }];
        #endif
    }

    [[UIApplication sharedApplication] registerForRemoteNotifications];

    // [END register_for_notifications]
}
return YES; }

我知道我可以在didRefreshRegistrationToken委托方法上获得femtoken。
该方法在模拟器上很好地启动,但从未在真实设备上触发 在[FIRApp配置]之后,我尝试使用此方法[[FIRInstanceID instanceID] token]获取fcmtoken,但仍然令牌为空。
我尽可能多地使用谷歌搜索,但在谷歌上得到了正确的答案。 请帮我。 任何帮助都会让我感激

0 个答案:

没有答案