gpt4 book ai didi

ios - AppDelegate 的 ViewController 内的 Preform 函数

转载 作者:行者123 更新时间:2023-11-28 20:23:00 26 4
gpt4 key购买 nike

AppDelegate 能否在收到推送通知后在 View Controller 中运行“功能”?

应用程序包含三个选项卡,第三个选项卡需要在应用程序收到推送通知时重新加载其 webview。

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {

}

最佳答案

是的,您需要为特定通知注册您的 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];
}

关于ios - AppDelegate 的 ViewController 内的 Preform 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15210678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com