作者valda (valda)
看板MacDev
标题[问题] pushnotification 的问题
时间Mon Nov 3 16:26:17 2014
如果我initial view controller 为A
A会push出B or C
B也会push出D
C也会push出E
当我接收到RemoteNotification时
不论当下任何的view controller
我都要push出一个特定的页面
目前我的做法是
在AppDelegate中
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
NSLog(@"%@",userInfo);
[[NSNotificationCenter defaultCenter] postNotificationName:@"test"
object:nil userInfo:nil];
}
然後每个viewcontroller加上
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleCurrentViewController:) name:@"test" object:nil];
}
- (void)handleCurrentViewController:(NSNotification *)notification {
PushNotificationViewController* pvc = [self.storyboard
instantiateViewControllerWithIdentifier:@"PushNotification"];
[self presentViewController:pvc animated:YES completion:nil];
}
但是如果我现在在B页面
因为B是由Apush出来的
所以我A跟B都会接收到NSNotificationCenter的讯息
都会触发
请问如何修改会比较好
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.248.186.235
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MacDev/M.1415003180.A.45D.html
1F:→ darktt: 在viewWillAppear的时候注册notification, 11/03 16:29
2F:→ darktt: viewWillDisappear的时候移除notificaiton。 11/03 16:29
3F:推 howdiun: 我是用一个独立的view去显示,忽略controller 11/04 09:09