Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tc14077 opened this issue Oct 11, 2022 · 2 comments

Comments

@tc14077
Copy link

tc14077 commented Oct 11, 2022

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?

@befirst
Copy link

befirst commented Nov 17, 2022

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 added a commit to befirst/flutter-apns that referenced this issue Nov 17, 2022
befirst added a commit to befirst/flutter-apns that referenced this issue Nov 17, 2022
befirst added a commit to befirst/flutter-apns that referenced this issue Nov 17, 2022
befirst added a commit to befirst/flutter-apns that referenced this issue Nov 17, 2022
@Caronesse
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants