Reputation: 107
I'm currently trying to reload my ViewController after opening a Notification from the notification center. In my AppDelegate I'm using this function:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateActive) {
//app is currently active, can update badges count here
}else if(application.applicationState == UIApplicationStateBackground){
}else if(application.applicationState == UIApplicationStateInactive){
//CODE
//REFRESH VIEW HERE, AFTER THE CODE ABOVE
}
}
How can this be done? This is my first experience with Objective-C, so please don't be rude with me ihihihi.
Thanks.
Upvotes: 0
Views: 375
Reputation: 7270
You can use the NSNotificationCenter
to let your UIViewController
know you have some updated data to show.
In the UIViewController
register to the notification center for your specific notification and then update your view.
In the app delegate:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"NEW_DATA_NOTIFICATION"
object:nil];
In your UIViewController
, in the viewDidLoad
:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveNewDataNotification:)
name:@"NEW_DATA_NOTIFICATION"
object:nil];
Also in your UIViewController
:
- (void) receiveNewDataNotification:(NSNotification *) notification {
if ([[notification name] isEqualToString:@"NEW_DATA_NOTIFICATION"]) {
NSLog(@"Received New Data Notification!");
// Update your view here...
}
}
Upvotes: 2