flutter-apns icon indicating copy to clipboard operation
flutter-apns copied to clipboard

[iOS] onResume callback get called when the app receiving the remote notification in background mode

Open tc14077 opened this issue 2 years ago • 2 comments

Hi folks, I am new to this package. I am working with the latest version of this package, flutter_apns_only: ^1.6.0.

I am getting confused about the definition of onResume. Under my understanding, the onResume is getting called, when the user taps on the notification with the app in the background. However, I figure out this onResume is also getting called while the app receives the remote notification. After deep diving into the implementation of the iOS platform code, I found this code snippet.

// this callback is getting called when the app receive the RemoteNotification
public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) -> Bool {
        let userInfo = FlutterApnsSerialization.remoteMessageUserInfo(toDict: userInfo)
        
        if resumingFromBackground {
            onResume(userInfo: userInfo) // this line making onResume call to flutter layer, however the app is not actually "resumingFromBackground", this flag is only indicating the app is in the "background"
        } else {
            channel.invokeMethod("onMessage", arguments: userInfo)
        }
        
        completionHandler(.noData)
        return true
    }

Maybe I have a wrong understanding of the onResume definition. If that is the case, can someone please suggest a way for me to identify whether the user is resuming the app through click the notification?

tc14077 avatar Oct 11 '22 07:10 tc14077

you are absolutely right, here is the official doc: https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623117-application

The first thing that it is deprecated since ios 10; The second:

If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:) method needs to get the remote notification payload data and respond appropriately.

befirst avatar Nov 17 '22 13:11 befirst

Hi,

I'm facing the same issue right now. Is there any way to use your package to react to the user clicking the notification? I understand, that I should implement the didReceive method as explained in the docs you linked. But how can I do this in Flutter with your package?

Caronesse avatar Jan 23 '23 12:01 Caronesse