首页 文章

无法从通过应用程序服务器连接的Firebase接收推送通知

提问于
浏览
0

我在firebase控制台中为apple APNs pushNotifications创建了一个新项目 . 我遵循了firebase文档中的所有说明,例如生成SSl证书并将p12证书(开发和 生产环境 )上传到firebase以及配置文件 . 并且还在Appdelegate中添加了所有必需的代码 . 并且还在功能中激活了pushNotifications,并且还在权利文件中将APNs环境设置为开发 .

当我从firebase通知消息发送示例消息时,我的iPhone(6)能够接收通知(通过FCM令牌和bundelId发送能够接收通知) . 但是从我的应用程序服务器使用相同的FCM令牌我无法接收通知,但是我的服务器端收到回复,因为通知发送了来自firebase的200代码 .

我无法从上周获得解决方案,也无法从移动端或服务器端获取问题 .

提前致谢....

1 回答

  • 0

    我找到了解决问题的方法 .

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    kGCMMessageIDKey = @"gcm.message_id";
    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;
            UNAuthorizationOptions authOptions =
            UNAuthorizationOptionAlert
            | UNAuthorizationOptionSound
            | UNAuthorizationOptionBadge;
            [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
            }];
    
            // For iOS 10 data message (sent via FCM)
            [FIRMessaging messaging].remoteMessageDelegate = self;
    #endif
        }
    
        [[UIApplication sharedApplication] registerForRemoteNotifications];
        // [END register_for_notifications]
    }
    
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    
    [FIRApp configure];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                 name:kFIRInstanceIDTokenRefreshNotification object:nil];
    return YES;
    }
    

    在上面的代码我没写

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                 name:kFIRInstanceIDTokenRefreshNotification object:nil];
    

    这一行,实际上不在firebase直接文档中 .

    并且还检查是否可以通过使用此方法获取将在控制台中打印的通知

    - (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
    // Print full message
    NSLog(@"Notification :%@", remoteMessage.appData);
    }
    

    但通知可能不会出现在通知屏幕上,因为apns formate是

    {"aps":{"alert":"Testing.. (0)","badge":1,"sound":"default"}}
    

    但是从服务器端来看,它可能是一种不同的格式 .

相关问题