Launch app from homescreen can't get remote pu

2019-03-30 03:16发布

问题:

Launch app from homescreen can't get remote push payload? But launch from Notification Center works.

At first, app is NOT running. After received remote push notification, user doesn't launch app with the notification at once. Then user taps on the notification in Notification Center to launch app, I can get the push payload from launchOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if(userInfo) {
        //do some works with push payload.
    }
}

But if the user launch app by tapping app icon from homescreen, I can't get the push payload from launchOptions, although application:didFinishLaunchingWithOptions: is called.

Again:

  1. App is NOT running.
  2. User doesn't launch app when received push notification.
  3. Later, launch app from Notification Center and get push payload from launchOptions.
  4. Launch app from homescreen can not get push payload from launchOptions.

Is this a bug in SDK? How can I get push payload by launching app from homescreen?

Thanks!

回答1:

You can't.

You only get the payload when launching from Notification Center because it means the user is interested on that notification.

For example, if I get a reply on Tweetbot and I want to see it, I tap on the notification, but if I only want to check my tweets, I open the app normally.

If the payload has information that the user HAS to receive, the app should contact your server and retrieve it.



回答2:

Yes, if the user launches the app by tapping the icon, the payload of the remote notification is lost.

It is not cool but it is the way it works at the moment.