Skip to content
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

Can't receive notifications in background #81

Closed
nvelin-zaggo opened this issue Aug 9, 2019 · 17 comments
Closed

Can't receive notifications in background #81

nvelin-zaggo opened this issue Aug 9, 2019 · 17 comments
Labels
ios relates to iOS platform support Support is being requested but not a necessarily a bug

Comments

@nvelin-zaggo
Copy link

I test my ionic application with https://cordova-plugin-fcm.appspot.com/

When the app is launched, everything works
When the app is not launched, i don't receive the notification, if i launch the application, the notification appears.
But i don't want this behavior, i prefer to receive the notification in the system banner.

I try with your test application and the behavior is the right one. I want the same !

I try to change content-available value, but nothing change

In IPhone Settings, i notice a difference.

IMG_0011

IMG_0012

So i suspect a wrong generation of my app.
I use "cordova-plugin-firebasex": "^6.0.4" with "@ionic-native/firebase-x": "^5.12.0"

In XCode, i have capabilities : "Background mode : Remote Notifications" and "Push Notifications" to true (checked by the generation, not me).

I try to compare ios platform folder between my app and the test app, it's seems to be very similar.

Any ideas ?

The log in XCode if it helps :

2019-08-09 14:32:46.805240+0200 Pharmajob[449:31246]  - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2019-08-09 14:32:46.876664+0200 Pharmajob[449:31187] Apache Cordova native platform version 5.0.1 is starting.
2019-08-09 14:32:46.876754+0200 Pharmajob[449:31187] Multi-tasking -> Device: YES, App: YES
2019-08-09 14:32:46.889354+0200 Pharmajob[449:31187] CDVWKWebViewEngine: trying to inject XHR polyfill
2019-08-09 14:32:46.912622+0200 Pharmajob[449:31187] CDVWKWebViewEngine will reload WKWebView if required on resume
2019-08-09 14:32:46.912740+0200 Pharmajob[449:31187] Using Ionic WKWebView
2019-08-09 14:32:46.913284+0200 Pharmajob[449:31187] [CDVTimer][console] 0.087023ms
2019-08-09 14:32:46.913426+0200 Pharmajob[449:31187] [CDVTimer][handleopenurl] 0.069976ms
2019-08-09 14:32:46.915540+0200 Pharmajob[449:31187] Unlimited access to network resources
2019-08-09 14:32:46.915638+0200 Pharmajob[449:31187] [CDVTimer][intentandnavigationfilter] 2.182007ms
2019-08-09 14:32:46.915751+0200 Pharmajob[449:31187] [CDVTimer][gesturehandler] 0.083089ms
2019-08-09 14:32:46.917351+0200 Pharmajob[449:31187] [CDVTimer][file] 1.553893ms
2019-08-09 14:32:46.917506+0200 Pharmajob[449:31187] Starting Firebase plugin
2019-08-09 14:32:46.921959+0200 Pharmajob[449:31187] [CDVTimer][firebaseplugin] 4.552960ms
2019-08-09 14:32:46.922105+0200 Pharmajob[449:31187] CDVIonicKeyboard: resize mode 1
2019-08-09 14:32:46.922935+0200 Pharmajob[449:31187] [CDVTimer][keyboard] 0.854969ms
2019-08-09 14:32:46.929265+0200 Pharmajob[449:31249] _hasPermission: NO
2019-08-09 14:32:46.929655+0200 Pharmajob[449:31187] [CDVTimer][splashscreen] 6.627917ms
2019-08-09 14:32:46.936333+0200 Pharmajob[449:31187] [CDVTimer][statusbar] 6.615996ms
2019-08-09 14:32:46.936488+0200 Pharmajob[449:31187] [CDVTimer][diagnostic] 0.098944ms
2019-08-09 14:32:46.937384+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_location] 0.867009ms
2019-08-09 14:32:46.938499+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_bluetooth] 1.080036ms
2019-08-09 14:32:46.938591+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_wifi] 0.054955ms
2019-08-09 14:32:46.938669+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_camera] 0.054955ms
2019-08-09 14:32:46.938739+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_notifications] 0.047922ms
2019-08-09 14:32:46.938796+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_microphone] 0.036001ms
2019-08-09 14:32:46.941203+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_contacts] 2.377987ms
2019-08-09 14:32:46.941308+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_calendar] 0.062943ms
2019-08-09 14:32:46.941372+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_reminders] 0.043035ms
2019-08-09 14:32:46.948204+0200 Pharmajob[449:31187] [CDVTimer][diagnostic_motion] 0.400901ms
2019-08-09 14:32:46.948245+0200 Pharmajob[449:31187] [CDVTimer][TotalPluginStartup] 35.122037ms
2019-08-09 14:32:46.961989+0200 Pharmajob[449:31187] GoogleService-Info.plist found, setup: [FIRApp configureWithOptions]
2019-08-09 14:32:46.976619+0200 Pharmajob[449:31187] [Crashlytics] Version 3.12.0 (136)
2019-08-09 14:32:47.084652+0200 Pharmajob[449:31187] didReceiveRegistrationToken: fr********
2019-08-09 14:32:47.091172+0200 Pharmajob[449:31187] FCM direct channel = true
2019-08-09 14:32:47.103891+0200 Pharmajob[449:31275] [NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor: <CTServiceDescriptor 0x282837d00, domain=1, instance=1>
2019-08-09 14:32:47.147908+0200 Pharmajob[449:31281] 6.3.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2019-08-09 14:32:47.159642+0200 Pharmajob[449:31282] 6.3.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60002000 started
2019-08-09 14:32:47.160139+0200 Pharmajob[449:31282] 6.3.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)
2019-08-09 14:32:48.098978+0200 Pharmajob[449:31187] Ionic Native: deviceready event fired after 624 ms
2019-08-09 14:32:48.419762+0200 Pharmajob[449:31281] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1f9a0] get output frames failed, state 8196
2019-08-09 14:32:48.419960+0200 Pharmajob[449:31281] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C1.1:2][0x107e1f9a0] get output frames failed, state 8196
2019-08-09 14:32:48.420217+0200 Pharmajob[449:31281] TIC Read Status [1:0x0]: 1:57
2019-08-09 14:32:48.420233+0200 Pharmajob[449:31281] TIC Read Status [1:0x0]: 1:57
2019-08-09 14:32:48.564748+0200 Pharmajob[449:31250] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C4.1:2][0x107e18550] get output frames failed, state 8196
2019-08-09 14:32:48.564858+0200 Pharmajob[449:31250] [BoringSSL] nw_protocol_boringssl_get_output_frames(1301) [C4.1:2][0x107e18550] get output frames failed, state 8196
2019-08-09 14:32:48.565064+0200 Pharmajob[449:31250] TIC Read Status [4:0x0]: 1:57
2019-08-09 14:32:48.565084+0200 Pharmajob[449:31250] TIC Read Status [4:0x0]: 1:57
@dpa99c dpa99c added ios relates to iOS platform support Support is being requested but not a necessarily a bug labels Aug 9, 2019
@dpa99c
Copy link
Owner

dpa99c commented Aug 9, 2019

2019-08-09 14:32:46.929265+0200 Pharmajob[449:31249] _hasPermission: NO

Looks as though you have not requested/granted permission for remote notifications on iOS

@nvelin-zaggo
Copy link
Author

nvelin-zaggo commented Aug 9, 2019

Thxs for the response,

I add hasPermission/grantPermission and i now i have _hasPermission: YES
Perfect

2019-08-09 15:33:22.166351+0200 Pharmajob[528:40244] grantPermission
2019-08-09 15:33:22.169543+0200 Pharmajob[528:40322] registerForRemoteNotifications
2019-08-09 15:33:22.169681+0200 Pharmajob[528:40322] _hasPermission: YES

But i haven't the expected :

  • If the app is in foreground, the notification is shown is the app : 👍
  • If the app is in background, the notification is not shown in the banner, when the app is launched, the notification is shown is the app : 👎
  • If the app is not launched at all, the notification is shown in the banner : 👍

An sample of my message :
I try to change content-available from 1 to 0, no effect

2019-08-09 15:37:57.233443+0200 Pharmajob[528:40244] didReceiveRemoteNotification: {
    action = updateMissions;
    aps =     {
        alert =         {
            body = "***";
            title = "***";
        };
        badge = 1;
        category = Notifications;
        "content-available" = 1;
        sound = "zaggo_sound.mp3";
    };
    "gcm.message_id" = 1565357876965034;
    "google.c.a.e" = 1;
    id = 24;
    message = "*****";
    messageType = notification;
    title = "****";
}

@dpa99c
Copy link
Owner

dpa99c commented Aug 9, 2019

Try to build & run the example app and use its FCM v1 API messaging client to send the predefined notification messages.
You should then be able to compare the behaviour of your app with the behaviour of the example app.

@rolinger
Copy link

rolinger commented Aug 11, 2019

I am having this issue too on iOS devices.

  1. App is open in foreground, data message is received, popup window shows message
  2. App is open in background, no status bar message received. But if move app to foreground, popup window shows the message
  3. App is closed, no status bar message is received. But if app is opened, popup windows shows the message.

In xcode project, capabilities Background Modes -> Remote Notifications is enabled as is "Push Notifications"

I then tested sending messages directly from Google FCM console to make certain it wasn't my server sending the message incorrectly and I get the same results as if it were sent from my server.

Cordova CLI: 9.0.0 (cordova-lib@9.0.1)
Gulp version: CLI version 3.9.1
Gulp local:
Ionic Framework Version: 1.3.4
Ionic CLI Version: 1.7.16
Ionic App Lib Version: 0.7.3
ios-deploy version: 1.9.4
ios-sim version: 8.0.1
OS: Mac OS X El Capitan
Node Version: v6.11.4
Xcode version: Xcode 10.1 Build version 10B61

I have my android version working but I am still using Cordova-plugin-firebase-lib as its working. My next android version I will move it over to this firebase version.

@rolinger
Copy link

in Xcode, after adding notification_foreground : true to my data payload, I get the following console message when a notification arrives. The app is in the foreground and still displays my custom popup window and the contents of the notification just fine, but this message appears:

processMessageForForegroundNotification: cannot show notification as permission denied

But when the app was installed I did accept push notifications...but oddly, when I go to iPhones settings -> notifications my app isn't listed. and when I go to settings -> myApp notifications isn't listed as an option for my app.

@rolinger
Copy link

rolinger commented Aug 12, 2019

figured out my issue. Turns out firebase has another breaking change in it. I was previously using cordova-plugin-firebase and the hasPermission and grantPermission call backs are different than the callbacks for firebasex. Now, granted, I was on an older version: cordova-plugin-firebase 0.1.25 "Google Firebase Plugin"

Previous version returned an object - which had a key of isEnabled - this is what my code was looking for and as a result when the app was installed it never did ask for permissions:

window.FirebasePlugin.hasPermission(function(data){
        if (data.isEnabled == false) {
           ...
        }
})

Where as the firebasex version just evaluates a boolean response:

window.FirebasePlugin.hasPermission(function(data){
        if (data == false) {
           ...
        }
})

Once I appended my code, my app asked for permissions properly and now everything works as it should.

that one took me for a spin Mr Dave Allen. The break changes section doesn't account for hasPermission/grantPermission changes so I just assumed my original Cordova-plugin-firebase JS was still going to work. :-)

@dpa99c
Copy link
Owner

dpa99c commented Aug 12, 2019

@rolinger Apologies, this was sloppiness on my part: I had updated iOS to return a boolean result to hasPermission() but actually forgot to do the same on Android (which still returns an object with isEnabled().
I'll update Android to align with iOS and document in the breaking changes section.

@dpa99c dpa99c closed this as completed in e0bb922 Aug 12, 2019
@dpa99c
Copy link
Owner

dpa99c commented Aug 12, 2019

This fix has been published as v6.0.5

@nvelin-zaggo this should resolve your issue (you may need to update you usage of hasPermission()) but let me know if it does not.

@rolinger
Copy link

@dpa99c - I guess I don't understand why the change to boolean at all - or even the onMessageOpen to onMessageReceived?. Keeping it with data.isEnabled keeps the code base aligned with all the other forked versions cordova-plugin-firebase, cordova-plugin-firebase-lib etc? Less breaking changes, less documentation to update, less people (like me) submitting break issues, etc etc. I suppose there must be a valid reason though.

Regardless, thanks.

@rolinger
Copy link

rolinger commented Aug 12, 2019

@dpa99c or anyone answer this 'related' question please? Trying to get iOS notifications to work I noticed on the iPhone that the devices token id changed a few times. And each time I had to register the new token ID for specific topics I am testing with - which got me thinking.

What happens to the user topic subscriptions when the device token changes? When I detect a token change, do I have to un-subscribe the users original token from all the topics they were subscribed to and then re-register the user for all the same topics using the new token? Or is this somehow auto-managed in the background -where FCM auto removes bad tokens and reassigns new tokens for all the user subscribed topics?

@svzi
Copy link

svzi commented Aug 16, 2019

@rolinger Very good questions, I'm currently searching for this kind of answers as well. Since migrating from cordova-plugin-firebase to cordova-plugin-firebasex I don't get any more push messages on iOS (Androids works like a charme, like before). I will need to do some more investigation next week, but the answers to your questions would help me as well.

@rolinger
Copy link

@svzi - I found answers to my own questions - you need to re-register the user for their existing topics. Currently I am now doing that through my back end server using php-fcm (https://github.com/rolinger/php-fcm) - so I pass the old tokenID to my server, unsubscribe the tokenID from all their subscribed topics, then subscribe the users new tokenID to all the same topics. I have requested a new feature to Dave Alden (firebasex author) to integrate this ability right into the plugin so it can all be managed easier and faster in real time directly from the app on the users phone.

As far as not getting iOS notifications, I fixed my issues. The firebasex plugin forces a new tokenID that had to be re-registered...as well, onNotificationOpen changes to onNotificationReceived in this plugin AND the iOS implementation is uses the return function(data) as a boolean, where as on Android function(data) is an object. Thus in your app, for iOS if (data == true) and on Android if (data.isEnabled == true) - once I fixed those two things (and the new tokenID) I was able to get notifications on iOS again.

@svzi
Copy link

svzi commented Aug 16, 2019

@rolinger Thanks a lot for reaching out, I really appreciate that. It looks like I did something wrong in my app for quite some time. Do I really need to re-subscribe to push-topics when the token has been refreshed ('onTokenRefresh()')? I never did that before, but that could possible explain my issues.

I didn't knew that the topic subscription is based on the device token. I thought it would be handled differently internally.

@rolinger
Copy link

@svzi - yeah, unfortunately you do need to re-register the users token every time it changes - it would be great if Firebase recognized a users token changed and simply updated everything for you.

When you register a user for a topic or a device group, the token ID is added to a managed list. if the topic does not yet exist, simply adding a user to the topic automatically creates the topic - so there isn't any new topic manage you have to do. Just subscribe and unsubscribe. I allow my users to subscribe/unsubscribe from within the app, but when the tokenID changes I have to pass the new tokenID back to my server, lookup all the users current subscriptions - then unsubscribe old and subscribe new token to those topics. Again, check out the php-fcm package I listed above on how to do this from the server. Hopefully Dave gets this added as a new plugin feature soon so we don't have to control all this from the server anymore.

@dpa99c
Copy link
Owner

dpa99c commented Aug 16, 2019

@rolinger I'll add the feature you requested (list user-specific FCM config) ASAP but it might be a week or so before I can implement it as I'm on vacation next week and my wife might throw things at me if I spend too much of it on a computer 😀

@rolinger
Copy link

@dpa99c - LOL You are lucky you even get to check the computer while on vacation. My wife won't even let me bring my computer when we go on holiday. Don't worry about the feature request - go relax and enjoy your vacation.

@svzi
Copy link

svzi commented Aug 16, 2019

@rolinger Thanks a lot, that makes a lot of sense. So I modified my coding accordingly and prepared a new beta version. Will play around with. Thanks again, for making me understand this crucial part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ios relates to iOS platform support Support is being requested but not a necessarily a bug
Projects
None yet
Development

No branches or pull requests

4 participants