发个广告:ios开发两年了,一步步走来 关注公众号一起进步
发现一篇文章 正好解决自己的问题,在此记录一下
- 方法一:
- -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
- if( ){
- PushViewController *push = [PushViewController alloc] init];
- [self.window.rootViewController presentViewController:push animated:YES completion:nil];
- }
- }
- 方法二:(个人感觉这个可靠些)
- 做一个基类:基类的viewwillappear里做操作,其它页面继承这个类
- 基本上想怎么跳就怎么跳:
- //-----------------------------------1
- @interface BasicViewController : UIViewController
- @end
- ....
- .m里
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotoMessageView:) name:@"gotoMessageView"object:nil];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"gotoMessageView" object:nil];
- }
- // 这里区分消息 进行页面跳转
- - (void) gotoMessageView:(NSNotification*) notification
- {
- //.....
- }
- //----------------2
- 其他viewcontroller:
- @interface AViewController : BasicViewController
- .....
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- }
- //----------3
- -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- {
- ......
- [[NSNotificationCenter defaultCenter] postNotificationName:@"gotoMessageView" object:nil];
- }