【发布时间】:2016-09-05 11:39:46
【问题描述】:
我正在使用 Firebase 注册主题并在 iOS 设备上发送推送通知。除了 iPhone 4 (iOS 7) 之外,一切正常,我没有收到任何通知。
我能够向包括 iPhone 4 (iOS 7) 在内的所有设备发送单个设备通知,问题仅在于主题推送通知。我的代码如下。
-(void)application:(UIApplication )application didRegisterUserNotificationSettings:(UIUserNotificationSettings )notificationSettings
{
[[FIRMessaging messaging] subscribeToTopic:@"/topics/mytopic"];
[application registerForRemoteNotifications];
}
-(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// iOS 8 Notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshCallback:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// iOS < 8 Notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshCallback:) name:kFIRInstanceIDTokenRefreshNotification object:nil];
[[FIRMessaging messaging] subscribeToTopic:@"/topics/mytopic"];
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
}
【问题讨论】:
标签: ios objective-c firebase firebase-cloud-messaging firebase-notifications