Using FCM for push notifications in iOS 10:
This is the snipper that's getting called after pushing a notification via our own API:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
if (userInfo[kGCMMessageIDKey]) {
NSLog(@"Message ID: %@", userInfo[kGCMMessageIDKey]);
}
completionHandler(UIBackgroundFetchResultNewData);
if(application.applicationState == UIApplicationStateBackground){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Bacgkround"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
else if(application.applicationState == UIApplicationStateActive){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Active"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
else if(application.applicationState == UIApplicationStateInactive){
[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"InActive"
description:@"Wassup"
type:TWMessageBarMessageTypeSuccess callback:^{
}];
}
}
When the app is active, above method gets called and UIApplicationStateActive case gets executed and I am showing a pop-up using a 3rd party library. When I press the Home button and push a notification, above method gets called and UIApplicationStateBackground gets executed but I am not sure how do I show a notification in the form of a banner?
Is this the method where I have to handle the notifications? If yes, how do I handle Background and Inactive states?