I'm using APNS via Azure Notification Hub to send notifications to iOS devices, so I can't use FCM for background processing in Flutter, but I am trying to replicate something similar to FCM's FirebaseMessaging.onBackgroundMessage(myMessageHandler)
as described in their manual.
So, let's say I have the following push message:
{
"aps" : {
"content-available" : 1
},
"acme1" : "bar",
"acme2" : 42
}
I need to pass values acme1
and acme2
to Flutter, process them and exit.
According to Apple doc's, to revive the app from UIApplication.State.inactive
I need to add following override to my AppDelegate.swift:
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
switch application.applicationState {
case .inactive:
// here I need to pass values to a handler
// within Flutter framework
break
default:
break
}
}
And this is where I'm spinning my wheels.
For the cases when the app is in the foreground (UIApplication.State.active) or in the background but still active (UIApplication.State.background), I'n using FlutterMethodChannel
to pass the data and that works great, but when the app was killed - I'm not sure what to do here. How do I start Flutter in headless mode, trigger a method and exit?