A short 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 the NSDictionary you received, from Apple's official documentation:
You can access the contents of the aps
dictionary—though you shouldn’t need
to in most cases—using the following
keys:
- alert—The value may either be a string for the alert message or a
dictionary with two keys: body and
show-view. The value of the former is
the alert message and the latter is a
Boolean (false or true). If false, the
alert’s View button is not shown. The
default is to show the View button
which, if the user taps it, launches
the application.
- badge—A number indicating the quantity of data items to download
from the provider. This number is to
be displayed on the application icon.
The absence of a badge property
indicates that any number currently
badging the icon should be removed.
- sound—The name of a sound file in the application bundle to play as an
alert sound. If “default” is
specified, the default sound should be
played.
The dictionary may also have
custom data defined by the provider
according to the JSON schema. The
properties for custom data should be
specified at the same level as the aps
dictionary. However, custom-defined
properties should not be used for mass
data transport because there is a
strict size limit per notification
(256 bytes) and delivery is not
guaranteed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…