I am trying to use postnotification but not able to implement it properly. This is what I have :
In ViewControllerOne.m
NSLog(@"PostNotification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"Connectivity" object:nil];
In ViewControllerTwo.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"Added Obeserver");
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(connectedTo:) name:@"Connectivity" object: nil];
}
-(void)connectedTo:(NSNotification *)notification
{
m_connectivity = @"Connected";
}
It seems that connectedTo function is not being called. This is because:
In another part of the code:
if ([m_connectivity isEqualToString:@"Connected"])
{
NSLog(@"Connected");
}
else
{
NSLog(@"NotConnected");
}
Not sure what my mistake is. Nee some guidance... Thanks..
EDIT:
ViewControllerOne.m is a class that other viewcontrollers subclass upon. It checks connectivity and when connected, I need to inform the other viewcontroller(ViewControllerTwo) that i am connected and take necessary action based on connectivity. So when connectivity changes, the notification will get posted but the viewcontroller might not been initialized at that point...