【问题标题】:Push notification Firebase causes crash推送通知 Firebase 导致崩溃
【发布时间】:2023-03-12 12:49:01
【问题描述】:

自从我们使用 xCode 8 和 OS 10 以来,我们在使用 Firebase 推送通知功能时遇到了一些问题。在我们的应用程序中,我们要求用户在第二次启动应用程序时启用推送通知,但在第一次(和下一次)启动后 10 秒后,它与此日志一起崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[FIRInstanceIDConfig setAllowGCMRegistrationWithoutAPNSToken:]: unrecognized selector sent to instance 0x170207740'

我们也尝试禁用 swizzling,但问题又出现了。

谁能告诉我们哪里出错了?

Firebase AppDelegate 代码:

#pragma mark - Notification
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    UALog(@"success to register notification");
#ifdef DEBUG
    [[FIRInstanceID instanceID] setAPNSToken:deviceToken
                                        type:FIRInstanceIDAPNSTokenTypeSandbox];
#else
    [[FIRInstanceID instanceID] setAPNSToken:deviceToken
                                        type:FIRInstanceIDAPNSTokenTypeProduction];
#endif
}

请求推送通知:

if ([popUpViewController isKindOfClass:[GSPushNotificationsPopupViewController class]]) {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:NSUD_ALREADY_DISPLAYED_NOTIF_MESSAGE];
    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
        UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
        [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {

        }];

        // For iOS 10 display notification (sent via APNS)
        [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
        // For iOS 10 data message (sent via FCM)
        [[FIRMessaging messaging] setRemoteMessageDelegate:self];
    }
}

【问题讨论】:

  • 也有这个问题。你找到解决办法了吗?
  • 你能在哪里解决问题?

标签: ios objective-c firebase apple-push-notifications firebase-cloud-messaging


【解决方案1】:

您是否已将应用的其他链接器标志添加到 -ObjC?您可以通过单击来执行此操作:项目名称 -> 构建设置 -> 其他链接器标志

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-16
    • 2018-03-10
    • 2015-10-10
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多