AppDelegate收到推送通知后是否可以在视图控制器中运行“功能”?
该应用程序包含三个选项卡,第三个选项卡需要在应用程序获得推送通知时重新加载其webview。
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
}
答案 0 :(得分:3)
是的,您需要为特定通知注册viewController
,例如在您收到远程通知的情况下,只需发布自定义通知,并在您的viewController中注册此通知/收听此通知,执行您要执行的方法。
收到remoteNotification
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[NSNotificationCenter defaultCenter] postNotificationName:@"pushNotification" object:nil userInfo:userInfo];
}
在viewController.m
注册此通知的viewcontroller
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushNotificationReceived) name:@"pushNotification" object:nil];
[super viewDidLoad];
}
然后实现选择器
-(void)pushNotificationReceived{
// do your stuff
}
最后不要忘记在dealloc
方法
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}