wizpanda / cordova-plugin-firebase-lib

This repository is moving & merging to https://github.com/wizpanda/cordova-plugin-firebase-lib to avoid confusion to developers.
https://www.wizpanda.com/
MIT License
68 stars 38 forks source link

iOS not displaying notification when app in background/closed #5

Open Dec- opened 5 years ago

Dec- commented 5 years ago

Describe the bug

Push notification working fine on Android but on iOS notification are not displaying when app is in background or closed. When app i opend and i push notification from Firebase console notification is visible but when i exit from app and do the same thing, notification is not visible.

Steps to reproduce the behavior:

  1. Go to Firebase Console
  2. Trigger notification
  3. iOS not displaying notification when app is closed or in background

Plugin Version

cordova-plugin-firebase-lib 3.0.0 "Google Firebase Plugin"

Smartphone (please complete the following information):

  1. Device: iPad 3
  2. OS: iOS10.3

Additional context

When i open the application after sending notification from Firebase console and app was in the background, suddenly notification is visible...

Can some1 help?

whoisaplex commented 5 years ago

This is also happening for my team. Been stuck for over a week.

sagrawal31 commented 5 years ago

Let us check that.

sagrawal31 commented 5 years ago

Well, I just tried it on one of our production iOS releases and it is working.

image

image

whoisaplex commented 5 years ago

Strange, once I put my app in the background, xcode says: Disconnected from FCM.

sagrawal31 commented 5 years ago

I Googled "disconnected from FCM" and got https://github.com/arnesson/cordova-plugin-firebase/issues/888

whoisaplex commented 5 years ago

Yes, been looking at that thread but none of the solutions seems to fix the problem.

swindex commented 5 years ago

Make sure your xCode project Capabilities include "Background mode" -> "Remote Notifications" Or add this to your config.xml

<platform name="ios">
     ......
        <config-file parent="UIBackgroundModes" platform="ios" target="*-Info.plist">
            <array>
                <string>remote-notification</string>
            </array>
        </config-file>
        <preference name="SplashScreen" value="screen" />
    </platform>
jm555jm commented 5 years ago

I fixed by add the following code:

AppDelegate+FirebasePlugin.m

swizzledDidFinishLaunchingWithOptions

add registerUserNotificationSettings

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tokenRefreshNotification:)
                                                 name:kFIRInstanceIDTokenRefreshNotification object:nil];
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge |
                                            UIUserNotificationTypeAlert |
                                            UIUserNotificationTypeSound
                                                                             categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    self.applicationInBackground = @(YES);

and add this function

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
    [application registerForRemoteNotifications];

}

and setup Background mode -> Remote Notifications in info.plist

it will work

sunhuafeng1992 commented 5 years ago

Does IOS background operation not receive notification have not been repaired yet? I did not solve my problem with the above scheme.

sunhuafeng1992 commented 5 years ago

I often encounter the error of Invalid Apns Credential, but the certificate is not expired. I hope you can help me.

eimermusic commented 5 years ago

There is also this which can mess up iOS notifications. The problem is not identical to what I have experienced but close enough so that this might be contributing.

//    window.FirebasePlugin.hasPermission((data) => {
//      if (!data.isEnabled) {
        window.FirebasePlugin.grantPermission();
//      }
//    });

I.e. make sure you do not call hasPermission because you need to call grantPermission regardless of the return value.