OGeek|极客世界-中国程序员成长平台

标题: ios - 如何处理来自应用委托(delegate)的 UIViewcontroller 中的通知? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:44
标题: ios - 如何处理来自应用委托(delegate)的 UIViewcontroller 中的通知?

我收到通知 appdelegate didReceiveRemoteNotification 但我想在 View Controller 中使用此有效负载数据怎么做?



Best Answer-推荐答案


有很多方法可以实现这一点,而且这个问题有点模糊。假设您的应用程序中有一个 View Controller ,当您的通知到达时它是事件的,也许最简单的方法是使用 NSNotification 将有效负载从应用程序委托(delegate)广播到您感兴趣的 View Controller 。

在您的 View Controller 中:

[[NSNotificationCenter defaultCenter] addObserver:self
    selectorselector(receivedRemoteNotification 
    name"RemoteNotification"
    object:nil];

并实现方法-receviedRemoteNotfication

然后,在您的应用代理的远程通知方法中:

 [[NSNotificationCenter defaultCenter] 
    postNotificationName"RemoteNotification" 
    object:payload];

关于ios - 如何处理来自应用委托(delegate)的 UIViewcontroller 中的通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31879301/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4