Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This question is a bit old, but I'll pop what I've found in here anyway.</p> <p>There are two methods you need to implement in your app delegate to check if your app was either launched from the remote notification (From when the app is not running on your device), or received the remote notification while running (in the background or foreground).</p> <p>First is a method that is already in your App Delegate:</p> <p><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions</code></p> <p>To check if this was launched from a remote notification, have some code similar to this:</p> <pre><code>// Check to see if launched from notification if (launchOptions != nil) { NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (dictionary != nil) { NSLog(@"Launched from push notification: %@", dictionary); // DO SOMETHING HERE } } </code></pre> <p>The other method you will need to implement is specifically for the case that your application for when your application is running:</p> <pre><code>-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSLog(@"Received notification: %@", userInfo); } </code></pre> <p>How you handle the notification from there is up to you, but that's how your app knows about it!</p> <p>In this second method, you can check the UIApplicationState of the passed application to find out if you were in the foreground or background.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload