firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Push notifications

Open demosthese opened this issue 9 years ago • 21 comments

With FirebaseInstanceID 2.0.3 push notifications don't work, but with 2.0.0 they do.

demosthese avatar Sep 26 '17 12:09 demosthese

Xcode 9 cant make it work also! tried messaging 2.0.0, 2.0.2 and 2.0.3

flash23 avatar Sep 26 '17 14:09 flash23

Can you both include more information on how you've set up Messaging?

morganchen12 avatar Sep 26 '17 17:09 morganchen12

This solved the problem

-(void)registerForPush
{
    UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if(granted && !error )
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                [UNUserNotificationCenter currentNotificationCenter].delegate = self;
                
                [[PushManager sharedInstance] registerNotificationCategories];
                
                if([FIRApp defaultApp] == nil)
                {
                    [FIRApp configure];
                }
                [FIRMessaging messaging].delegate = self;
                
                DDLogDebug( @"Push registration success." );
            });
        }
        else
        {
            DDLogDebug( @"Push registration FAILED" );
        }
    }];
} 

Before this blokc was outside

if([FIRApp defaultApp] == nil)
{
               [FIRApp configure];
 }
 [FIRMessaging messaging].delegate = self;

like this

-(void)registerForPush
{
    if([FIRApp defaultApp] == nil)
    {
        [FIRApp configure];
    }
    [FIRMessaging messaging].delegate = self;
    
    UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
    [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
        if(granted && !error )
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] registerForRemoteNotifications];
                [UNUserNotificationCenter currentNotificationCenter].delegate = self;
                
                [[PushManager sharedInstance] registerNotificationCategories];
                
                DDLogDebug( @"Push registration success." );
            });
        }
        else
        {
            DDLogDebug( @"Push registration FAILED" );
        }
    }];
}

it worked with XCode 8 and lower versions. There is some thread thing going on maybe....

flash23 avatar Sep 26 '17 20:09 flash23

There is a bug which has been fixed internally but hasn't been released yet, that is likely causing the issue.

For now, as a workaround you should always just call [[UIApplication sharedApplication] registerForRemoteNotifications]; as early as possible (this does not create a user permissions dialog, and should always give you an APNs token).

rsattar avatar Sep 26 '17 21:09 rsattar

thx

flash23 avatar Sep 26 '17 22:09 flash23

Also fixed for me, thanks !

Aurazion avatar Sep 27 '17 09:09 Aurazion

It's not fixing it for me. The messages don't get delivered if the app is in the background on iOS 11.

berlininsomniac avatar Sep 27 '17 09:09 berlininsomniac

@berlininsomniac Here is my fix in Swift if it can help you :

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        // [START set_messaging_delegate]
        Messaging.messaging().delegate = self
        // [END set_messaging_delegate]
        
        // Register for remote notifications. This shows a permission dialog on first run, to
        // show the dialog at a more appropriate time move this registration accordingly.
        // [START register_for_notifications]
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self
            
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })
        } else {
            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }
        
        application.registerForRemoteNotifications()
        // [END register_for_notifications]
        
        FirebaseApp.configure()

        return true
    }

Aurazion avatar Sep 27 '17 09:09 Aurazion

@berlininsomniac Not receiving messages in the background usually indicates an issue with the app configuration for APNs (i.e. check if application:didRegisterForRemoteNotificationsWithDeviceToken: is being called in your app delegate), or perhaps you are making a non-APNs request to the FCM API (i.e. if you are not sending a notification payload, and not including content_available=1).

There is also a known issue in iOS 11.0 where silent notifications (content_available=1) are arriving on the device, but not actually being delivered to the app.

rsattar avatar Sep 27 '17 20:09 rsattar

@rsattar It doesn't work anymore, without changing my code ... Waiting the fix release .... Thanks

Aurazion avatar Sep 28 '17 08:09 Aurazion

@Aurazion Confirming that [email protected] is fully operational when you add application.registerForRemoteNotifications() as the first line in didFinishLaunchingWithOptions.

Waiting for the final fix though, kinda ugly solution.

PaulRBerg avatar Sep 28 '17 20:09 PaulRBerg

FWIW, if you're locking temporarily to 2.0.0 you don't need to also call application.registerForRemoteNotifications() on app start.

rsattar avatar Sep 29 '17 00:09 rsattar

I can confirm that downgrading FirebaseInstanceID to 2.0.0 reenables pushes on iOS 11.

berlininsomniac avatar Sep 29 '17 09:09 berlininsomniac

How to downgrade the FirebaseInstanceID? I am just adding pod 'Firebase/Core', '4.0.1' pod 'Firebase/Messaging' if I do pod 'Firebase/Core', '4.0.1' pod 'Firebase/Messaging', '2.0.0' pod 'Firebase/InstanceID', '2.0.0' Which doesn't allow me to install pod. Any idea?

priyankamistry09 avatar Sep 29 '17 10:09 priyankamistry09

Try pod 'FirebaseInstanceID', '2.0.0'

PaulRBerg avatar Sep 29 '17 17:09 PaulRBerg

pod 'FirebaseInstanceID', '2.0.0', fixed the problem for me. Thanks for everyone in this feed. Saved my day :)

JussiSuojanen avatar Oct 02 '17 07:10 JussiSuojanen

Same for me with pod 'FirebaseInstanceID', '2.0.0' Thanks

Aurazion avatar Oct 02 '17 08:10 Aurazion

Fix released today in Firebase 4.3.0, FirebaseMessaging 2.0.4, and FirebaseInstanceID 2.0.4

paulb777 avatar Oct 03 '17 16:10 paulb777

I'm hitting this same issue today on: Using Firebase (4.6.0) Using FirebaseAnalytics (4.0.5) Using FirebaseAuth (4.3.2) Using FirebaseCore (4.0.11) Using FirebaseDatabase (4.1.1) Using FirebaseInstanceID (2.0.6) Using FirebaseMessaging (2.0.6)

Function boringssl_context_get_peer_sct_list: line 1757 received sct extension length is less than sct data length

dgaedcke avatar Nov 28 '17 19:11 dgaedcke

Indeed, it came back again.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Can't handle server close in non-started state.'

PaulRBerg avatar Nov 29 '17 00:11 PaulRBerg