【发布时间】:2016-09-14 17:00:12
【问题描述】:
在 Appdelegate.m 中添加 postNotification 方法
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if(application.applicationState == UIApplicationStateBackground) {
[[NSNotificationCenter defaultCenter] postNotificationName: @"SuggetionPushNotification" object:nil userInfo:userInfo];
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:[[UINavigationController alloc]
initWithRootViewController:[[SuggetionViewController alloc] init]]
leftMenuViewController:leftMenuViewController
rightMenuViewController:Nil];
[self.window makeKeyAndVisible];
appDel.window.rootViewController = container;
}
}
ViewController B (SuggetionViewController) 在 viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"SuggetionPushNotification"
object:nil];
- (void) receiveTestNotification:(NSNotification *) notification {
NSLog(@"working");
}
但是这里还没有触发通知,如果在同一个类中添加了 post 和 addobserver,那么只有它会触发。我做错了什么。我来自Send and receive messages through NSNotificationCenter in Objective-C?请帮忙
【问题讨论】:
-
参考这个链接stackoverflow.com/questions/4577255/…可能对你有帮助
-
@ShangariC 我也看到了这个。但还没有
标签: ios objective-c push-notification nsnotificationcenter mfslidemenu