Skip to content

Push notifications #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
demosthese opened this issue Sep 26, 2017 · 21 comments
Closed

Push notifications #315

demosthese opened this issue Sep 26, 2017 · 21 comments

Comments

@demosthese
Copy link

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

@flash23
Copy link

flash23 commented Sep 26, 2017

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

@morganchen12
Copy link
Contributor

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

@flash23
Copy link

flash23 commented Sep 26, 2017

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....

@rsattar
Copy link
Contributor

rsattar commented Sep 26, 2017

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).

@flash23
Copy link

flash23 commented Sep 26, 2017

thx

@Aurazion
Copy link

Also fixed for me, thanks !

@berlininsomniac
Copy link

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

@Aurazion
Copy link

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

@rsattar
Copy link
Contributor

rsattar commented Sep 27, 2017

@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.

@Aurazion
Copy link

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

@PaulRBerg
Copy link

@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.

@rsattar
Copy link
Contributor

rsattar commented Sep 29, 2017

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

@berlininsomniac
Copy link

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

@priyankamistry09
Copy link

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?

@PaulRBerg
Copy link

PaulRBerg commented Sep 29, 2017

Try pod 'FirebaseInstanceID', '2.0.0'

@JussiSuojanen
Copy link

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

@Aurazion
Copy link

Aurazion commented Oct 2, 2017

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

@paulb777
Copy link
Member

paulb777 commented Oct 3, 2017

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

@dgaedcke
Copy link

dgaedcke commented Nov 28, 2017

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

@PaulRBerg
Copy link

PaulRBerg commented Nov 29, 2017

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.'

@morganchen12
Copy link
Contributor

Please don't add 'me too' comments to closed issues. If you'd like to indicate you're also suffering from the same open issue, use GitHub's add a reaction feature. If it's a closed issue, try the solutions that have been listed and comment with what steps you took and what errors occurred.

@dgaedcke, your issue is not related to this issue and does not contain enough information to debug.

@PaulRBerg, your issue is not related to this issue. See #490

@firebase firebase locked and limited conversation to collaborators Nov 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests