Push notification data not getting when app launched directly by clicking app icon

后端 未结 4 1391
攒了一身酷
攒了一身酷 2021-02-15 04:09

I have a scenario in which app will get push notification and need to show that messages in home screen of my app, for that i saved the message array into user defaults from my

相关标签:
4条回答
  • 2021-02-15 04:42

    In scenario 1. NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; here remoteNotif return nil as you enter into the app through triggering app icon.

    In scenario 2. You can get push notification info through the following method

    -(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
    {
          if (userInfo) {
    
              [self handlePushMessage:userInfo];
          }
    }
    
    0 讨论(0)
  • 2021-02-15 04:49
    1. if app is in killed state and a notification came and user triggeres the app through the app icon (not from push notification )

      • If the app is in killed state then the push notification payload can only be handed over to the app when the user taps the push notification itself. If the user launches the app from app icon then the notification payload will not be passed to the application
    2. if app is in background and notification came and user enters to app through app icon (not from push message ) in this case also

      • if you are targeting iOS7 and up then you need to enable background mode for remote notifications. Please check below link in order to get notification payload even when app is in background

      didReceiveRemoteNotification not working in the background

      The above mentioned app delegate method gets called when the app is in foreground,Background and suspended state.

    There is no way to get the notification payload when app is killed and when the app icon is directly clicked instead of push notification in notification center.

    0 讨论(0)
  • 2021-02-15 04:54

    This is a common issue: if the user does not open your app by means of the displayed notification, there is no* way of getting the related information.

    * A possible solution employed by many apps is to check with a remote server for unread notifications (e.g. check for an unset read-date field).

    0 讨论(0)
  • 2021-02-15 04:54

    Enable "Remote Notifications" under background modes in capabilities in target settings. This will fetch the notification data even when the app is in the background. Also, make sure to implement:

    -(void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler;
    

    in your app delegate.

    0 讨论(0)
提交回复
热议问题