我会通过打开parse发送的推送通知来设置我们特定视图的开放。使用IOS 8。 我怎样才能做到这一点?? 我用了这段代码:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
[navController.visibleViewController.navigationController pushViewController:notificationViewController animated:YES];
}
答案 0 :(得分:0)
我使用此代码
- (UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController* tabBarController = (UITabBarController*)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
这样叫:
- (void) doSomething {
UIViewController *topViewController = [self topViewController];
NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
[topViewController.navigationController pushViewController:notificationViewController animated:YES];
}
不要忘记将此代码放在您的应用程序上:didFinishLaunchingWithOptions :(当用户触摸关闭应用程序的通知时)
NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (!remoteNotification) {
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification) {
[self doSomething];
}
} else {
[self doSomething];
}