Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>First scenario:</strong></p> <pre><code>- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { NSLog (@"APNS: notification received: %@", userInfo); NSString *message = nil; id alert = [userInfo objectForKey:@"aps"]; if ([alert isKindOfClass:[NSString class]]) { message = alert; } else if ([alert isKindOfClass:[NSDictionary class]]) { message = [alert objectForKey:@"alert"]; } if (message) { if (![message isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"notification" message: message delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } } </code></pre> <p><strong>Second scenario:</strong></p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog (@"LAUNCH OPTIONS: %@",launchOptions); id remoteNotificationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (remoteNotificationValue) { NSString *message = nil; id alert = [remoteNotificationValue objectForKey:@"aps"]; if ([alert isKindOfClass:[NSString class]]) { message = alert; } else if ([alert isKindOfClass:[NSDictionary class]]) { message = [alert objectForKey:@"alert"]; } if (message) { if (![message isEqualToString:@""]) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"notification" message: message delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } } .... </code></pre> <p>Of course you might want to make a special method that handles notifications and is called from both scenarios (with <code>NSDictionary</code> * parameter) so your code would be more readable. Sometimes APNS notifications are useful also when app is running - empty notification (with no payload) might be used to trigger the data synchronization with server to avoid polling for example.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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