How do I tell if my iPhone app is running when a Push Notification is received?

前端 未结 5 488
栀梦
栀梦 2020-12-04 14:39

I am sending Push Notifications to my iPhone app, and I\'d like a different set of instructions to execute depending on whether the app is already launched or not. I\'m new

5条回答
  •  离开以前
    2020-12-04 15:26

    The Apple documentation for push notifications explains this:

    However, there are two situations where applicationDidFinishLaunching: is not a suitable implementation site:

    • The application is running when the notification arrives.
    • The notification payload contains custom data that the application can use.

    In the first case, where the application is running when iPhone OS receives a remote notification, you should implement the application:didReceiveRemoteNotification: method of UIApplicationDelegate if you want to download the data immediately. After downloading, be sure to remove the badge from the application icon. (If your application frequently checks with its provider for new data, implementing this method might not be necessary.)

    This means that if your application:didReceiveRemoteNotification: delegate method is called, your app is running.

提交回复
热议问题