Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

iOS Notification not received in background mode #258

Closed
fsandreau opened this issue Jan 12, 2017 · 13 comments
Closed

iOS Notification not received in background mode #258

fsandreau opened this issue Jan 12, 2017 · 13 comments
Milestone

Comments

@fsandreau
Copy link

I use this awesome plugin and I just added the Firebase notification feature, It work only if the application state is activated (foreground). When the application is suspended or closed, I don’t receive any notification sent from firebase notification UI. Once the application is launched, all notifications are pushed.
Any ideas ?

@thomasmoon
Copy link

I am experiencing this too with the latest version of the plugin, though it has worked for me before.

These settings have to be added to the Info.plist, but other than that, not sure why this would be?

<key>UIBackgroundModes</key> <array> <string>remote-notification</string> </array>

@fsandreau
Copy link
Author

Happy to see that I'm not the only one.
Note that the same code works great with Android.

@sudhanshu-15
Copy link

#237 is the same issue.

@EddyVerbruggen
Copy link
Owner

I just tested with the demo app again and confirmed I was able to reproduce this issue (would only receive a notification in the foreground), but after doing this the pushes started appearing in the background as well.

Watch the devicelog closely right after the "This app wants to send you notifications" consent popup is accepted. That's when helpful hints may be emitted by Firebase as to why notifications may not work. Like in this case I got "Failed to fetch APNS token Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo={NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}" and realized I had to toggle that switch in Xcode.

@EddyVerbruggen EddyVerbruggen added this to the 3.9.2 milestone Jan 20, 2017
EddyVerbruggen added a commit that referenced this issue Jan 20, 2017
iOS Notification not received in background mode #258
iOS: Push Notifications not working in Background or when application is reopened #243
Notification message not shown when app is in the background #237
@EddyVerbruggen
Copy link
Owner

Please update to 3.9.2 and take note of the update messaging instructions, let me know if issues remain afterwards.

@thomasmoon
Copy link

Hey Eddy, thanks for the update!

The background notifications work perfectly with plugin version 3.9.2, my Xcode settings were apparently correct.

The new instructions about the entitlements file are useful and the file seems to be copied to the write place when reinstalling the ios platform, however for some reason Xcode doesn't recognize the push notification settings from that file. I had to open Xcode and toggle the switch for those, any idea why? The background notifications on the other hand are recognized automatically from the Info.plist file.

@manishmlv50
Copy link

Hey Eddy,
Thank for a wonderful plugin. I am facing the same issue in android. I get the notification and the addOnMessageReceivedCallback() method is called when the app is active, but when the app is in the background, no notifications are received. I am facing this issue in android. Please help.

@EddyVerbruggen
Copy link
Owner

@thomasmoon I'm afraid this no longer automatically works - so you need to correct that in Xcode indeed. I'm pondering a hook that will fix the entitlements though.

@manishmlv50 Most often folks have issues with iOS not Android. Is there any code I can look at?

@manishmlv50
Copy link

The code for the onMessageReceivedCallback is as follow :
firebase.init({
persist: true,
onPushTokenReceivedCallback: function(token) {
// console.log("Firebase push token: " + token);
},
onMessageReceivedCallback: function(message) {
alert(JSON.stringify(message));
console.log("Title: " + message.title);
console.log("Body: " + message.body);
// if your server passed a custom property called 'foo', then do this:
console.log("Value of 'foo': " + message.data.foo);
},
onAuthStateChanged: (data) => {
console.log(data.loggedIn ? "Logged in to firebase" : "Logged out from firebase");
}
}).then(
(instance) => {
console.log("firebase.init done");
// var token = com.google.firebase.iid.FirebaseInstanceId.getInstance().getToken();
// console.log( token.to );
firebase.addOnPushTokenReceivedCallback((token)=> {
console.log("Firebase push token: " + token);
});
},
(error) => {
// console.log("firebase.init error: " + error);
}
);

The code for sending the notification is as follow :

http.request({
  url: "https://fcm.googleapis.com/fcm/send",
  method: "POST",
  headers: { 
    "Content-Type": "application/json" ,
    "Authorization" : "key=XXXXXXXXXXX"
  },
  content: JSON.stringify({ 
    "to": "/topics/news", 
    "collapse_key" : news,
    "data": { 
        "test": "test'
    }, 
    "notification": notification
  })
}).then(function (response) {
  // push notification response
  console.log("Push Notification Response");
  console.dump(response);
}, function (e) {
    console.log("Error occurred " + e);
});

I am getting the notification when the app is open. But when the app is closed, I figured out the way to show notification. But the onMessageReceivedCallback method is not called when the app is opened from the notification

@EddyVerbruggen
Copy link
Owner

What was the problem with not receiving the notification while the app was in the background? May be helpful to others to know.

@manishmlv50
Copy link

The issue is not with the plugin but android avc: denied { unlink } for pid=19488. So if I disconnect the device from debug mode. I get the notifications. But when I tap on that notification, the callback for messages is not called.

@manishmlv50
Copy link

Application launched on: Wed Mar 01 2017 12:30:18 GMT+0530 (IST)
JS: Error in firebase.addOnMessageReceivedCallback: Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
JS: granted

EXCEPTION: Uncaught (in promise): Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
JS: ORIGINAL STACKTRACE:
JS: Error: Uncaught (in promise): Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
JS: at resolvePromise (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:416:31)
JS: at file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:393:13
JS: at file:///data/data/com.one.develop/files/app/tns_modules/nativescript-plugin-firebase/firebase.js:278:7
JS: at new ZoneAwarePromise (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:465:29)
JS: at Object.firebase.addOnMessageReceivedCallback (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-plugin-firebase/firebase.js:252:10)
JS: at new AppComponent (file:///data/data/com.one.develop/files/app/app.component.js:53:18)
JS: at new Wrapper_AppComponent (/AppModule/AppComponent/wrapper.ngfactory.js:6:18)
JS: at _View_AppComponent_Host0.createInternal (/AppModule/AppComponent/host.ngfactory.js:15:28)
JS: at _View_AppComponent_Host0.AppView.create (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:9170:25)
JS: at ComponentFactory.create (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/node_modules/@angular/core/bundles/core.umd.js:5809:40)
JS: Unhandled Promise rejection: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192) ; Zone: angular ; Task: Promise.then ; Value: Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192) Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fra
JS: gment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)
JS: at Object. (file:///data/data/com.one.develop/files/app/tns_modules/console/console.js:316:33)
JS: at JSON.stringify ()
JS: at Console.createDump (file:///data/data/com.one.develop/files/app/tns_modules/console/console.js:307:26)
JS: at Console.dump (file:///data/data/com.one.develop/files/app/tns_modules/console/console.js:342:25)
JS: at file:///data/data/com.one.develop/files/app/app.component.js:54:21
JS: at file:///data/data/com.one.develop/files/app/tns_modules/nativescript-plugin-firebase/firebase.js:271:9
JS: at new ZoneAwarePromise (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-angular/zone.js/dist/zone-nativescript.js:465:29)
JS: at Object.firebase.addOnMessageReceivedCallback (file:///data/data/com.one.develop/files/app/tns_modules/nativescript-plugin-firebase/firebase.js:252:10)
JS: at new AppComponent (file:///data/data/com.one.develop/files/app/app.component.js:53:18)
JS: at new Wrapper_AppComponent (/AppModule/AppComponent/wrapper.ngfactory.js:6:18)
JS: Error: Uncaught (in promise): Error: java.lang.NoSuchMethodError: no static method "Ljava/lang/Long;.toString()Ljava/lang/String;"
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1047)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1028)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1018)
JS: com.tns.FragmentClass.onCreateView(android.app.Fragment.java)
JS: android.app.Fragment.performCreateView(Fragment.java:2053)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
JS: android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
JS: android.app.BackStackRecord.run(BackStackRecord.java:833)
JS: android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
JS: android.app.Activity.performResume(Activity.java:6090)
JS: android.app.ActivityThread.performResumeActivity(ActivityThread.java:3131)
JS: android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3173)
JS: android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
JS: android.app.ActivityThread.access$900(ActivityThread.java:163)
JS: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
JS: android.os.Handler.dispatchMessage(Handler.java:102)
JS: android.os.Looper.loop(Looper.java:135)
JS: android.app.ActivityThread.main(ActivityThread.java:5536)
JS: java.lang.reflect.Method.invoke(Native Method)
JS: java.lang.reflect.Method.invoke(Method.java:372)
JS: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397)
JS: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1192)

I hope this helps in identifying the problem

@EddyVerbruggen
Copy link
Owner

@manishmlv50 Can you show me what's on this line? file:///data/data/com.one.develop/files/app/app.component.js:53:18

EddyVerbruggen added a commit that referenced this issue Apr 18, 2017
iOS Notification not received in background mode #258
iOS: Push Notifications not working in Background or when application is reopened #243
Notification message not shown when app is in the background #237
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

4 participants