Reputation: 11
I'm trying to send a Push Notification like any other messaging platform like WhatsApp, Telegram, etc. The message is supposed to be End-to-End Encrypted, so the encrypted message needs to be decrypted before showing in the notification banner in the mobile app using flutter_local_notifications. But the data messages are not received on iOS when the app is terminated. Only when a notification
object with title
or body
is added in the payload, the message is received on iOS even in background or terminated state. But results in two notification banners for a message.
Read this in FlutterFire GithHub Discussion without success.
Push Notifications (Firebase) are triggered via AWS SNS: Mobile Push-Notifications
. Here's the code invoking Push Notification with payload.
const payload = {
GCM: JSON.stringify({
data: {
message: message
},
android: {
priority: "high"
},
content_available: true
}),
};
const params = {
Message: JSON.stringify(payload),
TargetArn: ENDPOINT_ARN,
MessageStructure: 'json',
};
const publishCommand = new PublishCommand(params);
I highly doubt if WhatsApp, Telegram are actually using Push Notifications in their apps but some kind of background-service. But the background processing is still unpredictable on iOS. So what should be the notification solution for a E2EE chat app built using Flutter?
Upvotes: 0
Views: 115
Reputation: 91
You will have to upgrade your flutter version for me 3.22.3
FirebaseMessaging.onBackgroundMessage
But we should be careful of many points
You should not open WebSocket
You should get your messages by making one HTTP request
You should do your work quickly as the IOS system will close your app at any time
this point happened to me: when checked for the internet it closed the app and didn't complete the work
Sometimes the IOS system will block your app when you try many times so it sometimes doesn't work after sending a lot of FCM
please read this comment also about how sometimes the message may not received in ios https://github.com/firebase/flutterfire/issues/9563#issuecomment-1259318869
this is backend server side
admin.messaging().send({data,token,android: {priority: 'high',data,}, apns: {
payload: {
aps: {
contentAvailable: true,
mutableContent: true,
priority: 'high',
},
},
headers: {
'apns-push-type': 'background',
'apns-priority': '5',
'bundleIdentifier': 'com.example.packageId', // Replace with
your app's bundle identifier
},
}, })
Upvotes: 0