[firebase_messaging]: iOS background message handling not triggered after time when terminating app
Is there an existing issue for this?
- [X] I have searched the existing issues.
Are you aware of the differences between iOS and Android background message handling?
- [X] I understand that iOS and Android background messages behave differently, and I've designed my application with that in mind.
Do you have an active Apple Developer account?
- [X] I have an active Apple Developer account.
Are you using a physical iOS device to test background messages?
- [X] I am using a physical iOS device to test background messages.
Have you enabled "Remote Notifications" & "Background Mode" (Checking options for "Background Processing" & "Remote Notifications") in your app's Xcode project?
Have you created an APNs key in your Apple Developer account & uploaded this APNs key to your Firebase console?
Have you disabled method swizzling for Firebase in your app?
Are you sending messages to your app from the Firebase Admin SDK?
from postman (i tried many combination but nothing works):
{
"data": {
"title": "You have new message",
"body": "New message(s) recieved."
},
"content_available": true,
"notification" : {
},
"apns": {
"payload": {
"aps": {
"contentAvailable": true,
"sound" : "default",
"mutableContent": true
}
},
"headers": {
"apns-push-type": "background",
"apns-priority": "5"
}
},
    "to": ""
}
Have you requested permission from the user to receive notifications?
- [X] I have the relevant permission to receive notifications.
Have you used the 'Console' application on your macOS device to check if the iOS device's system is throttling your background messages?
``
Additional context and comments
Also i tried to handle silent push natively and got the same result, the handling works very well when the app in background and terminated status from few moments and after that it will not works again !! native snippet code :
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Messaging.messaging().appDidReceiveMessage(userInfo)
if Auth.auth().canHandleNotification(userInfo) {
completionHandler(.noData)
return
}
// sample notification for testing
let content = UNMutableNotificationContent()
content.title = "Hi there"
content.body = "Just test"
content.sound = UNNotificationSound.default
let request = UNNotificationRequest(identifier: "helloNotification", content: content, trigger: nil)
UNUserNotificationCenter.current().add(request) { (error) in
if let error = error {
print("Error adding notification request: \(error.localizedDescription)")
}
}
// resent to dart side
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let notificationChannel = FlutterMethodChannel(name: "notificationHandler", binaryMessenger: controller.binaryMessenger)
var dataToSend: [String: Any] = [:]
if let text = userInfo["text"] as? String {
dataToSend["text"] = text
}
// Convert the dictionary to NSDictionary
let nsDataToSend = NSDictionary(dictionary: dataToSend)
// Pass the NSDictionary to Dart
notificationChannel.invokeMethod("handleRemoteMessage", arguments: nsDataToSend)
}
from postman (i tried many combination but nothing works):
@IhabZaidi Please try to use the node js admin sdk as mentioned in the plugin example and check using it, if you still get same behavior or not.
okey after days of googling and search i found out that if i want to wakeup the app when it in terminated status should use voip push notification to notify user with a incoming call and that what im looking for but still now i cant send voip push successfully, i used the messaging node package and used node-apn but does not work.. snippet codes time : admin messaging :
// as silent push notifs
payload = {
data: {
'dp': '' + message['DP'],
'title': 'Incoming Video Call...',
'body': '' + message['CALLERNAME'] || recipient.data().nickname,
'TIME': '' + message['TIME'],
'TYPE': '' + message['TYPE'],
'UID': '' + message['UID'],
'CallID': '' + message['CallID'],
}
}
let options = {
"priority": 'high',
"contentAvailable": true,
};
and this approach is for senging voip push notification :
var options = {
token: {
key: "AuthKey_xxxx.p8",
keyId: "xxxxx",
teamId: "dddddd"
},
production: false
};
var apnProvider = new customApn.Provider(options);
let deviceToken = "llll"
var note = new customApn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 20;
note.topic = "com.app.here.voip";
note.payload = {
"aps": { "content-available": 1 },
"handle": "1111111",
"callerName": "TEster",
"uuid": "xxxxxxxxxxxxxxxxxxxxxx",
};
note.priority = 5;
note.pushType = 'voip';
apnProvider.send(note, deviceToken).then( (result) => {
res.status(200).send(result);
});
as conclusion i found that if i want to notify users there is a incoming call when they closed the app the only way is via voip push, if i wrong just tell me
i found out that if i want to wakeup the app when it in terminated status
@IhabZaidi According to the documentation, if the app is in terminated state and if swiped away, then we need to manually reopen the app for background message to start working . See if this helps in your case or not.
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start working again.
Also check if this helps further or not.
Hey @IhabZaidi. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
was it somehow resolved ?
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start working again.
Seems "deprecated" for some guys claimed to have it to work !
what's more when i swipe the app from the recent app list and the app is then in terminated/killed mode, the background code is still called !
My problem is the iPhone reboot that breaks all that background treatment :( Im desesparatly searching for a solution to that problem :(
anyone ?
Hey @IhabZaidi. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@IhabZaidi if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.