I know it's a bit odd but I've written this code that launches a specific view controller when the user clicks on a push notification. The code works perfectly when I run it on my device, but the second I unplug my device from Xcode and run it again the code doesn't execute and the view controller doesn't open when I click on a push notification.
Here is the code I have for opening my view controller in my Appdelegate.m
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
if(apsInfo) {
//there is some pending push notification, so do something
//in your case, show the desired viewController in this if block
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert"
message:[NSString stringWithFormat:@"%@ ",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]
delegate:self cancelButtonTitle:@"Done"
otherButtonTitles:nil];
[alertView show];
UIViewController *vc = self.window.rootViewController;
NotificationViewController *pvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"Alerts"];
[vc presentViewController:pvc animated:YES completion:nil];
}
}
if more info is needed please say so.
Thanks in advance, Cheers
UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:@"myStoryBoardName" bundle:nil];
NotificationViewController *pvc = [mystoryboard instantiateViewControllerWithIdentifier:@"Alerts"];
[self presentViewController:pvc animated:YES completion:nil];
UIStoryboard *storyboard;
storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.window.rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"Alerts"];
[self.window makeKeyAndVisible];
Try this one.. It should work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.