如果您发送channelID
推送通知,则可以channelID
从 userInfo 字典中检索。正如midhere所说 -
1) 当应用程序在后台运行时,当应用程序在前台运行时
application:didReceiveRemoteNotification:
方法将调用如下。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive)
{
//opened from a push notification when the app was on background
NSString channelID = [[userInfo objectForKey:@"aps"] objectForKey:@"channelID"];
NSLog(@"channelID->%@",channelID);
}
else if(application.applicationState == UIApplicationStateActive)
{
// a push notification when the app is running. So that you can display an alert and push in any view
NSString channelID = [[userInfo objectForKey:@"aps"] objectForKey:@"channelID"];
NSLog(@"channelID->%@",channelID);
}
}
2) 当应用程序未启动(关闭)时,application:didFinishedLaunchWithOptions
将调用方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
//opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil)
{
NSString channelID = [[userInfo objectForKey:@"aps"] objectForKey:@"channelID"];
NSLog(@"channelID->%@",channelID);
}
}
else{
//opened app without a push notification.
}
}