收到推送通知时更新UITableView

时间:2014-11-08 09:44:39

标签: ios objective-c

我有一个简单的应用程序作为RSS阅读器。 如何在接收推送通知时更好地组织更新订阅源?

1)从FirstViewController拨打didReceiveRemoteNotification并更新Feed?

2)将值从didReceiveRemoteNotification发送到 FirstViewController ,并在 FirstViewController 更新Feed?

1 个答案:

答案 0 :(得分:1)

我从AppDelegate发布NSNotification

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"appDidReceiveRemoteNotification"
     object:self
     userInfo:userInfo];
}  

在我的ViewControllers中收听该通知,例如

- (void)remoteNotificationReceived:(NSNotification *)aNotification
{
    NSDictionary *userInfo = aNotification.userInfo;

    // Update your views here
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(remoteNotificationReceived:)
                                                 name:@"appDidReceiveRemoteNotification"
                                               object:nil];
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}