【问题标题】:FCM Topics - Notifications not received on iPhone 4 (iOS 7)FCM 主题 - iPhone 4 (iOS 7) 上未收到通知
【发布时间】: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


    【解决方案1】:

    请将此用于

          // Register for remote notifications
          if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
            // iOS 7.1 or earlier
            UIRemoteNotificationType allNotificationTypes =
            (UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge);
            [application registerForRemoteNotificationTypes:allNotificationTypes];
          } else {
            // iOS 8 or later
            // [START register_for_notifications]
            UIUserNotificationType allNotificationTypes =
            (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
            UIUserNotificationSettings *settings =
            [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
            // [END register_for_notifications]
          }
    
     // [START configure_firebase]
      [FIRApp configure];
      // [END configure_firebase]
    
      // Add observer for InstanceID token refresh callback.
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                   name:kFIRInstanceIDTokenRefreshNotification object:nil];
    

    【讨论】:

    • 如何在 iOS 7 中订阅主题?
    • [[FIRMessaging 消息] subscribeToTopic:@"/topics/news"];
    • 在 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:) name:kFIRInstanceIDTokenRefreshNotification object:nil] 处给出错误;
    • NSInvalidArgumentException',原因:'-[FIRA_AppDelegate-1473079437035 tokenRefreshNotification:]:无法识别的选择器发送到实例 0x17696d90'
    猜你喜欢
    • 2018-12-04
    • 2019-08-17
    • 1970-01-01
    • 2021-10-30
    • 2021-02-11
    • 2017-02-25
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多