Push notification Firebase causes crash
Asked Answered
A

1

11

We have some troubles with Firebase Push Notifications function since we using xCode 8 and OS 10. In our application, we asked user to enable push notification on second launch of app but after 10 seconds after the first (and next) launch, it crashes with this log :

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

We also try to disable swizzling but the problem occurred again.

Can someone tell us where we are going wrong?

Firebase AppDelegate Code :

#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
}

Push notification asked :

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];
    }
}
Ambulatory answered 2/12, 2016 at 15:34 Comment(2)
Also having this issue. Did you figure out the solution ?Solar
Where you able to solve the problem?Sherrilsherrill
C
1

Have you added your app's other linker flags to -ObjC? You can do this by clicking: Project Name -> Build Settings -> Other Linker Flags

enter image description here

Clearsighted answered 3/1, 2017 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.