在你的 AppDelegate.h 添加这个:
//Under where you have <UIKit/UIKit.h>
extern NSString *localReceived;
在您的 AppDelegate.m 中添加以下内容:
//All the way on top where you import your viewControllers
NSString *localReceived = @"localReceived";
在您的 AppDelegate.m- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification;
方法中添加以下内容:
[[NSNotificationCenter defaultCenter] postNotificationName:localReceived object:self];
确保您的 viewController 是一个 navigationController
如果不是,请执行以下操作 - 将这段代码添加到您的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
:
UINavigationController *nvcontrol = [[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:nvcontrol.view];
[window makeKeyAndVisible];
现在 - 在您的 viewController.m 中将其添加到您的 -viewDidLoad 函数中
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localAction) name:localReceived object:nil];
创建一个 -(void) localAction 并在该方法中添加您的 navigationController 代码以推送到下一个 View Controller!
希望这对你有用。对我来说就像一个魅力