Open Veronika-dev opened 1 year ago
Hi, Unfortunatley it's not possible to use Firebase messaging on iOS and APNS at the same time.
On iOS TalkJS uses APNS for push notifications, and cannot use Firebase.
So:
If you urgently need to fix this problem, my suggestion would be to fork this project, remove the flutter_apns_only
dependency, and all the APNS related stuff from notification.dart
.
Keep in mind that doing so disables the push notifications for TalkJS.
Actually, it's impossible because I need notifications.
Maybe you have other thoughts? Do I have to replace all my FCM with APNS?
If replacing FCM with APNS is an option for you, then it's absolutely the way to go
However, maybe there are some other decisions?
Actually as I see I can get notifications in foreground but FirebaseMessaging.onBackgroundMessage
. It isn't called and I can't get any of data in background. But notifications are shown correctly.
And I am sorry for misleading, after some research I found that the following code doesn't break FCM. But only I add talkjs again to my project, FirebaseMessaging.onBackgroundMessage
stops being called.
<key>flutter_apns.disable_swizzling</key>
<true/>
I'm not well in it, so could you please help me and clarify if it can be fixed? Or what do I have to do? Give me the direction, please.
Thanks
Hey there, my name is Victor. I'm a developer here at TalkJS. The setting you highlighted that disables swizzling is only necessary if you DO NOT need Firebase messaging for iOS push notifications. link. So in your case, you should remove this from your Info.plist
.
Regarding, FirebaseMessaging.onBackgroundMessage
not getting called, could you share with me a sample of the json data you are sending to Firebase so that I can help debug the issue.
Hi Victor @vickz84259,
if I don't use disable_swizzling, I get an error Firebase PlatformException(channel-error, unable to establish connection on channel., null, null)
and firebase_messaging doesn't work at all.
This is full data from FirebaseMessaging.onMessage
when the app is opened. Do you need this one?
{
senderId: null,
category: null,
collapseKey: null,
contentAvailable: true,
data: {
body: {
"callType": "EMERGENCY",
"callId": 231,
"type": "client_create_call",
"callInfo": {
"questSubj": "..."
},
"clientDetails": {
"firstName": "...",
"lastName": "..."
},
"isSilent": false
}
},
from: null,
messageId: 1688656717966683,
messageType: null,
mutableContent: true,
notification: {
title: "...",
titleLocArgs: [],
titleLocKey: null,
body: "...",
bodyLocArgs: [],
bodyLocKey: null,
android: null,
apple: {
badge: null,
subtitle: null,
subtitleLocArgs: [],
subtitleLocKey: null,
imageUrl: null,
sound: null
},
web: null
},
sentTime: null,
threadId: null,
ttl: null
}
if I don't use disable_swizzling, I get an error Firebase PlatformException(channel-error, unable to establish connection on channel., null, null) and firebase_messaging doesn't work at all.
Give me a moment as I confirm the exact scenario under which this happens.
This is full data from FirebaseMessaging.onMessage when the app is opened. Do you need this one?
Nope. I need the json data your server sends to Firebase. Not what Firebase sends to the device.
Thanks Victor.
Backend developer told me that he used fb api to form the request.
He gave me this code of the forming. And he will try to find the way to log json api tomorrow if it is necessary. But maybe now it will be useful.
ApnsConfig
apnsConfig=ApnsConfig.builder().setAps(Aps.builder().setMutableContent(true).setContentAvailable(true).build()).build();
MulticastMessage msg = MulticastMessage.builder()
.addAllTokens(tokens).setApnsConfig(apnsConfig)
.putData("body", mapper.writeValueAsString(data))
.setNotification(notification)
.build();
BatchResponse res= fcm.sendMulticast(msg);
First of all my apologies. When I said:
The setting you highlighted that disables swizzling is only necessary if you DO NOT need Firebase messaging for iOS push notifications. So in your case, you should remove this from your Info.plist.
I was wrong. My assumption was that that key disables swizzling even for the FirebaseMessaging module. However it onlly disables swizzling for flutter_apns
. So you should have the key in your Info.plist
.
Regarding FirebaseMessaging.onBackgroundMessage
not getting called, this is an issue with the payload being sent to Firebase. Without having content-available: 1
and mutable-content: 1
in your payload for iOS. The background message handler won't get called.
You can read more here: https://github.com/firebase/flutterfire/issues/9381 and https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943360
But as you can see from my comment the backend developer enabled both content-available
and mutable-content
.
And as I mentioned in the other comment, FirebaseMessaging.onBackgroundMessage
works great until I add talkjs-flutter package into my application.
Once I remove it from pubspec.yaml
file, call flutter pub get
and restart my application FirebaseMessaging.onBackgroundMessage
works fine!
I can say the same about swift method in ios/Runner/AppDelegate.swift
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Foundation.Data) {
Messaging.messaging().apnsToken = deviceToken
print("DEVICETOKEN", deviceToken)
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
I see the printed message in console when there are no talkjs package in my app. And the message stops showing when I add it.
So it seems a problem in blocking background notification methods by the talkjs-flutter package. Could you tell me, what you think about it?
Hi Victor @vickz84259, could you please tell me the status? It's really urgent one
Sorry I hadn't seen your follow up comment. Let me investigate further. I'll get back to you once I find the source of the bug.
@vickz84259 Hi Victor, Sorry for pushing but I would like to know status of the task. Could you clarify please?
@vickz84259 Hello, Victor! Any updates on this issue?
Hi, thank you for the project!
I need firebase cloud messaging to get notifications in background. But it didn't work because of needed settings by talkjs-flutter project
flutter_apns.disable_swizzling: true
If I remove it, there is a problem
Firebase PlatformException(channel-error, unable to establish connection on channel., null, null)
It breaks the key feature in my application.
Please, help me to fix it. It's really urgent.
Thank you!