How do I know if a user has opened a notification app with the background of iOS 7 remote notification?

According to didReceiveRemoteNotification, when in the background , we used to process the user opening the application by pressing the action button on the push notification (or scrolling through the push notification, depending on how the user sees the push notification) by implementing -application:didReceiveRemoteNotification: and then checking inside the method whether the application applicationState inactive.

IOS 7 has a new remote-notification background mode that allows the application to perform background extraction when a remote notification is displayed to the user (without the need for the user to make any notification). To support this mode, you must implement the -application:didReceiveRemoteNotification:fetchCompletionHandler: .

The documentation for -application:didReceiveRemoteNotification: says that if your application delegate implements the application:didReceiveRemoteNotification:fetchCompletionHandler: , then "the application object calls this method instead." This means that we can no longer use -application:didReceiveRemoteNotification: to handle remote notifications, since it will not be called.

We should probably put the processing logic in application:didReceiveRemoteNotification:fetchCompletionHandler: but the previous trick for processing it no longer makes sense - previously we depended on the only way for -application:didReceiveRemoteNotification: be called when the application is inactive if the user clicked the action button in the notification to open the application. However, now the whole point of the remote-notification background mode is that it can call application:didReceiveRemoteNotification:fetchCompletionHandler: in the background every time a remote notification is received before the user does something with it.

So, how can we now say when the user opens the application using the action button in the notification?

+6
source share
2 answers

You still check the status of the application in application:didReceiveRemoteNotification:fetchCompletionHandler:

  • UIApplicationStateBackground - the application is in the background receiving a push notification
  • UIApplicationStateInactive - the application opens from the user by clicking on the notification
+6
source

I used this delegate function to add 「Notification Number」 .

Because our server does not send an icon to our Clients. Then I used a weird method to add a 「Notification Number」 with this delegate function, and also add code to switch the UIViewController in this function.

I found out when I use the push Notification server for my test application, and the status of the test application is in the background, even I use Twitter or Safari.

My test App also switches the UIViewController to another UIViewController after I click Notification on the server.

0
source

Source: https://habr.com/ru/post/956893/


All Articles