Contrôleur de vue ouverte lorsque APNS est reçu dans iOS

Hey je suis nouveau sur iPhone et j'ai essayé d'utiliser une notification push Apple. Fondamentalement, ce que je veux faire est que lorsque l'user clique sur le message de notification push reçu, alors j'ai besoin d'ouvrir un controller de vue spécifique. J'ai ajouté des données personnalisées avec le paramètre key "type" à mon JSON de charge utile, donc au nom de la valeur du type de notification, j'ai besoin d'ouvrir un controller de vue particulier au lieu du controller de vue principal.

voici mon file JSON:

{"aps":{"alert":"This is testing message","type":"Notify","badge":1,"sound":"default"}} 

mon code est:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; splashViewController = [[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil]; self.window.rootViewController = splashViewController; [self.window makeKeyAndVisible]; return YES; } - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { //this will call when your app will get any notification from server. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; NSDictionary *aps = (NSDictionary *)[userInfo objectForKey:@"aps"]; NSMutableSsortingng *notificationType = [aps objectForKey:@"type"]; NSLog(@"notification type is = %@", notificationType); //For redirect to the view UIViewController *viewController; if([notificationType isEqualToSsortingng:@"Notify"]){ //Notify updates UpdatesViewController *uvc1 = [[UpdatesViewController alloc] initWithNibName:@"UpdatesViewController" bundle:nil]; viewController = uvc1; } else { //Voting & QA VotingViewController *votingViewController = [[VotingViewController alloc] initWithNibName:@"VotingViewController" bundle:nil]; viewController = votingViewController; } [self.window.rootViewController presentViewController:viewController animated:YES completion:NULL]; } 

Mon code ne présente pas d'autre controller de vue. Comme mentionné dans mon code, je reçois deux types de service web (type de notification) 1. Notifier et 2. Voter d'Apple. Je ne sais pas comment présenter le controller de vue spécifique au nom du type de notification, si le type est "notifier" alors j'ai besoin d'ouvrir UpdatesViewController sinon il ouvrira un autre viewcontroller. Si quelqu'un sait comment faire cela, aidez-moi s'il vous plaît.

Merci.

 //For redirect to the view UIViewController *uvc; if([notificationType isEqualToSsortingng:@"Notify"]){ UIViewController *updates = [[UpdatesViewController alloc] initWithNibName:@"UpdatesViewController" bundle:nil]; // add updates specific data updates.data = [aps objectForKey:@"data"]; uvc = updates; } else if([notificationType isEqualToSsortingng:@"Voting "]) { UIViewController *voting = [[VotingViewController alloc] initWithNibName:@"VotingViewController" bundle:nil]; // add voting specific data voting.data = [aps objectForKey:@"data"]; uvc = voting; } [self.window.rootViewController presentViewController:uvc animated:YES completion:NULL]; 

vous devriez vérifier les didFinishLaunchingWithOptions dans didFinishLaunchingWithOptions . didReceiveRemoteNotification ne fonctionne que lorsque l'application est en cours d'exécution ou suspendue.