You want to read Local and Remote Notification Handling
Mainly in the deletion of the application you want to implement:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
and
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
And handle startOptions / userInfo for notification data.
How do I usually process data:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if (userInfo) { [self processRemoteNotification:userInfo]; } [window addSubview:viewController.view]; [window makeKeyAndVisible]; return YES; } - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { [self processRemoteNotification:userInfo]; }
The format for user information is documented in the "Payload" section .
eg. the βapsβ key will give you another NSDictionary, and then searching for the βalertβ key will give you the warning message that was displayed. In addition, there will also be any user data that you send in the JSON payload.
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"]; NSString *alertMsg = @""; NSString *badge = @""; NSString *sound = @""; NSString *custom = @""; if( [apsInfo objectForKey:@"alert"] != NULL) { alertMsg = [apsInfo objectForKey:@"alert"]; } if( [apsInfo objectForKey:@"badge"] != NULL) { badge = [apsInfo objectForKey:@"badge"]; } if( [apsInfo objectForKey:@"sound"] != NULL) { sound = [apsInfo objectForKey:@"sound"]; } if( [userInfo objectForKey:@"Custom"] != NULL) { custom = [userInfo objectForKey:@"Custom"]; }
source share