How can I handle push notification when my application is down

how can I handle push notification when my application is not running I'm developing for reference ios3.please

+4
source share
1 answer

A brief example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary *tmpDic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; //if tmpDic is not nil, then your app is launched due to an APNs push, therefore check this NSDictionary for further information if (tmpDic != nil) { NSLog(@" - launch options dict has something "); NSLog(@" - badge number is %@ ", [[tmpDic objectForKey:@"aps"] objectForKey:@"badge"]); NSLog(@" - "); } 

Edited: About NSDictionary obtained from Apple's official documentation:

You can access the contents of the aps dictionary, although you do not need it in most cases - using the following Keys:

  • alert. The value can be either a string for the notification message, or a dictionary with two keys: body and show view. The value of the first is a warning message, and the last is a Boolean (false or true). If false, Warning Show button is not displayed. by default, the "View" button is displayed which, if the user deletes it, launches the application.
  • - A number indicating the number of data items to download from the provider. This number is displayed on the application icon. The absence of an icon property indicates that any number is currently the Icon icon should be removed.
  • sound - the name of the sound file in the set of applications for playback in the form of an audio signal. If "default" is specified, the default sound should be played.

The dictionary may also have user data defined by the provider according to the JSON schema. properties for user data must be specified at the same level as the aps Dictionary. However, user-defined properties should not be used for mass data transfer, since there is a strict size for each notification (256 bytes), and delivery is not guaranteed.

+14
source

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


All Articles