Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

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

Open
Dec- opened this issue May 31, 2019 · 11 comments
Open

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

Dec- opened this issue May 31, 2019 · 11 comments

Comments

@Dec-
Copy link

Dec- commented May 31, 2019

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
Copy link

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

@sagrawal31
Copy link
Member

Let us check that.

@sagrawal31
Copy link
Member

sagrawal31 commented Jun 3, 2019

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

image

image

@whoisaplex
Copy link

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

@sagrawal31
Copy link
Member

I Googled "disconnected from FCM" and got arnesson#888

@whoisaplex
Copy link

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

@swindex
Copy link

swindex commented Jun 18, 2019

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
Copy link

jm555jm commented Jun 19, 2019

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
Copy link

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

@sunhuafeng1992
Copy link

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

@eimermusic
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants