- 方法一:
- -(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];
- }
收到推送通知後頁面跳轉,當程序在後臺,無論進入後臺之前在哪個界面,點擊收到的推送,跳轉到指定界面的2個思路:
發個廣告:ios開發兩年了,一步步走來 關注公衆號一起進步
發現一篇文章 正好解決自己的問題,在此記錄一下
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.