Cordova-plugin-firebase: disconnected from FCM when app goes to background(ios12)

Created on 29 Sep 2018  路  10Comments  路  Source: arnesson/cordova-plugin-firebase

when app goes to background, disconnected from FCM by itself. of course can鈥檛 receive any push notification. works well on ios11.

runtime messaging iOS

Most helpful comment

Not sure if it helps you, but in my case it worked. I had issue when push notifications sporadically stopped arriving. Many other users of the app reported about same issue. After reinstall of the app they were starting to arrive again, but sooner or later they were stopping to arrive again.

Anyway, in the code for iOS I was calling hasPermissions prior to grantPermissions. hasPermission was returning TRUE because push notifications were allowed previously. But I've decided to comment the block with hasPermissions and left only grantPermissions. The modal for Push Notification permissions did not appear as it was expected, but notifications started to arrive again.
That's my final code:

    pushNotificationPermissions() {
        if (!this.platform.is('ios')) {
            return new Promise((s) => s());
        }
        // return this.firebase.hasPermission().then(data => {
        //     this.firebase.logEvent('PushNotificationPermissions', data);
        //     if (data.isEnabled) {
        //         return true;
        //     }
             return this.firebase.grantPermission();
        // });
    }

Strange behavior, but it works. Let it be...

All 10 comments

You might compile with Xcode 10.

Try to compile with legacy build system .

see this post https://github.com/apache/cordova-ios/issues/407.

on ios you should use grantPermission(); function. without this you can't receive background notifications.

You might compile with Xcode 10.

Try to compile with legacy build system .

see this post apache/cordova-ios#407.

thank you for your reply.. I tried. not work for me.

on ios you should use grantPermission(); function. without this you can't receive background notifications.

I already used grantPermission().

@lthivk Are you including a click_action in your notification? If so, try removing it. I found a Firebase issue were if you used a click_action in the notification it would not work in the background.

You might compile with Xcode 10.
Try to compile with legacy build system .
see this post apache/cordova-ios#407.

thank you for your reply.. I tried. not work for me.

after I tried many times, finally, It worked. thank you very much.

Would be nice if @lthivk tell us what was wrong at the end.

For me it was the suggestion of the op here that worked apache/cordova-ios#407

I was building it using with

ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"

but had XCode set to New Build System. Once I changed that, notifications worked again.

Not sure if it helps you, but in my case it worked. I had issue when push notifications sporadically stopped arriving. Many other users of the app reported about same issue. After reinstall of the app they were starting to arrive again, but sooner or later they were stopping to arrive again.

Anyway, in the code for iOS I was calling hasPermissions prior to grantPermissions. hasPermission was returning TRUE because push notifications were allowed previously. But I've decided to comment the block with hasPermissions and left only grantPermissions. The modal for Push Notification permissions did not appear as it was expected, but notifications started to arrive again.
That's my final code:

    pushNotificationPermissions() {
        if (!this.platform.is('ios')) {
            return new Promise((s) => s());
        }
        // return this.firebase.hasPermission().then(data => {
        //     this.firebase.logEvent('PushNotificationPermissions', data);
        //     if (data.isEnabled) {
        //         return true;
        //     }
             return this.firebase.grantPermission();
        // });
    }

Strange behavior, but it works. Let it be...

Not sure if it helps you, but in my case it worked. I had issue when push notifications sporadically stopped arriving. Many other users of the app reported about same issue. After reinstall of the app they were starting to arrive again, but sooner or later they were stopping to arrive again.

Anyway, in the code for iOS I was calling hasPermissions prior to grantPermissions. hasPermission was returning TRUE because push notifications were allowed previously. But I've decided to comment the block with hasPermissions and left only grantPermissions. The modal for Push Notification permissions did not appear as it was expected, but notifications started to arrive again.
That's my final code:

    pushNotificationPermissions() {
        if (!this.platform.is('ios')) {
            return new Promise((s) => s());
        }
        // return this.firebase.hasPermission().then(data => {
        //     this.firebase.logEvent('PushNotificationPermissions', data);
        //     if (data.isEnabled) {
        //         return true;
        //     }
             return this.firebase.grantPermission();
        // });
    }

Strange behavior, but it works. Let it be...

After hours trying every other method, this is what worked for me... Thank you very much!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielAccorsi picture DanielAccorsi  路  3Comments

Zrnik picture Zrnik  路  3Comments

danielpalen picture danielpalen  路  5Comments

michaelreiser picture michaelreiser  路  5Comments

arunkatariaoodles picture arunkatariaoodles  路  4Comments