无法接收来自Firebase 3.2.0主题的iOS推送通知 [英] Cannot receive push notification on iOS from Firebase 3.2.0 topics
问题描述
我遵循Google的 https://firebase.google .com / docs / notifications / ios / console-topics#receive_and_handle_topic_messages 订阅我iOS应用上的Firebase主题。
func application(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool {
FIRMessaging.messaging()。subscribeToTopic(/ topics / Notifications)
homeViewController = UINavigationController(rootViewController:HomeViewController())
UINavigationBar.appearance()。translucent = false
window = UIWindow(frame:UIScreen.mainScreen()。bounds)
window?.rootViewController = homeViewController
window ?. makeKeyAndVisible()
return true
}
然而,当我发送一个话题从Firebase控制台推送通知。读范范辛但是当我从控制台发送推送通知给用户段时,推送工作正常。当我检查Xcode控制台时,我看到这个FIRMessaging错误。
2016-05-31 11:11:47.893:< ; FIRMessaging /警告>无法订阅主题:/主题/带有标记的通知:(null)
我尝试过搜索对于这个错误,但没有找到任何运气。我不确定这是否是导致我的应用程序无法从主题获得任何推动的问题。
有没有人有这个问题,并知道如何解决它?
<看起来可能是你打电话给 subscribeToTopic
太早。
$ $ p $ code> FIRApp.configure()
这样可以确保所有Firebase服务都能正确设置和初始化。 下一步,您需要等待一点点订阅主题。您的客户需要先将您的应用注册到APN和FCM,以确保它可以接收通知。这涉及到一个网络电话,这意味着您的应用程序第一次启动时,您不能订阅主题。相反,我建议将代码放入应用程序中:didRegisterUserNotificationSettings
处理程序。像这样的东西:
$ $ p $ - (void)application:(UIApplication *)application didRegisterUserNotificationSettings :( UIUserNotificationSettings *)notificationSettings {
NSLog(@Hooray!我注册了!);
[[FIRMessaging messaging] subscribeToTopic:@/ topics / cool_users];
编辑:和Swift版本...
func application(application:UIApplication,didRegisterUserNotificationSettings notificationSettings:UIUserNotificationSettings){
print(Hooray!I'm registered!)
()/ $ p
$ b $ / code $I followed the tutorial by google on https://firebase.google.com/docs/notifications/ios/console-topics#receive_and_handle_topic_messages to subscribe to a Firebase topic on my iOS app.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
FIRMessaging.messaging().subscribeToTopic("/topics/Notifications")
let homeViewController = UINavigationController(rootViewController: HomeViewController())
UINavigationBar.appearance().translucent = false
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.rootViewController = homeViewController
window?.makeKeyAndVisible()
return true
}
However, when I send a topic push notification out from the Firebase console. I could not receive any push notifications. But when I send out push notification to user segment from the console, the push is working perfectly. When I check the Xcode console, I am seeing this FIRMessaging error.
2016-05-31 11:11:47.893: <FIRMessaging/WARNING> Cannot subscribe to topic: /topics/Notifications with token: (null)
I've tried to search for this error but have no luck finding anything. I am not sure if this is the problem that is causing my app to not receive any push from topics.
Does anyone have this issue and know how to solve it?
解决方案 Looks like maybe you're calling subscribeToTopic
too early.
First, before you set up any Firebase call, make sure you call
FIRApp.configure()
That will ensure that all Firebase services are properly set up and initialized.
Next, you're going to need to wait just a bit to subscribe to topics. Your client needs to first register your app with both APNs and FCM to ensure that it can receive notifications. That involves a network call, which means you can't subscribe to topics when your app first launches.
Instead, I'd recommend putting that code into your application:didRegisterUserNotificationSettings
handler instead. Something like this:
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSLog(@"Hooray! I'm registered!");
[[FIRMessaging messaging] subscribeToTopic:@"/topics/cool_users"];
}
Edit: And the Swift version...
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
print("Hooray! I'm registered!")
FIRMessaging.messaging().subscribeToTopic("/topics/swift_fans")
}
这篇关于无法接收来自Firebase 3.2.0主题的iOS推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!