Changes for iOS 10

There are new delegate methods introduced in iOS 10 to track notification and display in foreground state as well. To track notifications in background state, you need to enable background mode in the capabilities. Above all these you need to activate push notification in the capabilities. This will add entitlement files to your app target.

AppDelegate Changes

Define Macros

#import <UserNotifications/UserNotifications.h>
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

Registering for push notifications

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  TargetActClient *tc = [TargetActClient sharedInstance];//WithServer:@"192.168.1.4:10000"];
  tc.target = self;
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
  [tc doPushRegistration];
  [tc initializeCarouelActions];
  return YES;
}

Sending the push token to Gamooga servers

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
   TargetActClient *tc = [TargetActClient sharedInstance];
   [tc updatePushRegistrationId:deviceToken];
}

Handling Push Notification

Notifications are delivered while the app is in foreground, background or not running state. We can handle them in the following delegate methods.
Handling push notifications on non ios 10 devices

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO( @"10.0" ) )
{
  NSLog( @"iOS version >= 10. Let NotificationCenter handle this one." );
   // set a member variable to tell the new delegate that this is background
   return;  
}
  NSLog(@"Received: %@",userInfo);
}

The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  NSDictionary *userInfo = notification.request.content.userInfo;
   if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
   NSLog(@"%@", userInfo);
   }
completionHandler(UNNotificationPresentationOptionAlert);
}

The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from applicationDidFinishLaunching:
NOTE:This method is specifically required for carousel and slider push to work.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
   NSDictionary *userInfo = response.notification.request.content.userInfo;
   if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  NSLog(@"%@", userInfo);
  NSLog(@"%@", response.actionIdentifier);
   }
  completionHandler();
}

Handling Deeplinks

For Push notifications deeplinks should be handled in the method didReceiveNotificationResponse:withCompletionHandler: as described below. You can get the deeplink url and then pass it to openUrl: and then you should get a callback in the application:openUrl:options where you can handle the opening of a specific page.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
   NSDictionary *userInfo = response.notification.request.content.userInfo;
   if ([userInfo objectForKey:@"deeplinkurl"]) {
       NSURL *url = [NSURL URLWithString:userInfo[@"deeplinkurl"]];
       dispatch_async(dispatch_get_main_queue(), ^{
           [[UIApplication sharedApplication] openURL:url];
       });
   }
   completionHandler();
}