0

我在Firebase控制台中为苹果APN推送通知创建了一个新项目。我遵循Firebase文档中的所有说明,例如生成SSl证书和上传p12证书(开发和生产)到firebase以及配置文件。并且还在Appdelegate中添加了所需的全部代码。并且还在功能中激活了PushNotifications,并且在授权文件APNs环境中设置为开发。无法从通过应用服务器连接的Firebase接收推送通知

当我从firebase通知消息发送示例消息时,我的iPhone(6)能够接收通知(通过FCM令牌发送并且还可以通过bundelId接收通知)。但是从具有相同FCM令牌的应用程序服务器中,我无法接收通知,但是我的服务器端获得了答复,因为发送通知时发送了来自Firebase的200个代码。

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

在此先感谢....

+0

您配置完成。 –

+0

我作为获取我的控制台日志无法获取APNS令牌Error Domain = com.firebase.iid Code = 1001“(null)” – Jeevan

回答

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

这一行,其实这是不火力直接文档。

而且还要检查是否可以使用此方法

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

但通知可能不会通知屏幕上出现,因为APNS酸盐是得到通知将在控制台打印

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

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

相关问题