我有一个简单的应用程序作为RSS阅读器。 如何在接收推送通知时更好地组织更新订阅源?
1)从FirstViewController
拨打didReceiveRemoteNotification
并更新Feed?
2)将值从didReceiveRemoteNotification
发送到 FirstViewController ,并在 FirstViewController 更新Feed?
答案 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];
}