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.
}
}