iOS Rich Push Integration

Enhance the presentation of push notifications with the inclusion of Images, GIFs, Audio and Video for iOS 10 and above iPhones.

1. Adding Extensions

In iOS 10, two frameworks have been introduced for handling push notifications with content. You can have a push notification with image, gif, audio, and video. Apart from that, you can also have your custom UI for notifications. For this, the payload can be modified and used to download content before the notification is drawn. You simply need to follow the steps given below to add two of the extensions targets for handling these notifications: Service Extension and Content Extension.

Before proceeding, make sure to download all the files to be used from this link. You should have these files with you:

  1. TacNotifications.framework
  2. NotificationService
  3. NotificationVC
Notification Service Extension

Service extension is the target extension where you get a callback when a push is delivered to the device. You can download and create attachments here. If you fail to download the content and pass it to contentHandler within a certain time, default standard notification will be drawn.

Adding Service extension
  1. Add an iOS target, choose Notification Service extension and proceed. Add a product name, select the language as swift and finish. When created, you will be prompted to activate the target. Once activated, you can see two files added, NotificationService.swift and Info.plist. gamooga push settings gamooga push settings

  2. Please delete the NotificationService.swift file and Info.plist.
  3. Add these files from downloaded NotificationService
  4. Add TacNotifications.framework to extension target. Do not add it to main app target.
Adding Content Extension
  1. Add an iOS target and choose Notification Content extension and proceed. Add a product name, select the language as swift and finish. When created, you will be prompted to activate the target. Once activated, you can see 3 files added NotificationVC.swift, MainInterface.storyboard and Info.plist. gamooga push settings gamooga push settings

  2. Please delete NotificationViewController.swift, MainInterface.storyboard and Info.plist.
  3. Add these files from downloaded NotificationVC
  4. You must create a bridging header and add iCarousel.h in Bridging-Header so that the objective C files can be used in your extension targets.
  5. Add TacNotifications.framework to extension target. Do not add it to main app target.

Finally, make sure you add TacNotifications.framework to ‘Embedded Binaries’ section of your main App’s General settings.

Note: Do not add TacNotifications.framework to 'Linked frameworks and libraries' section of your main App's General settings. This will cause a crash on devices below iOS 10.

2. Implementing Push Open and Push Received

For devices operating with iOS 10 and above, it is possible to implement callbacks in order to measure and track the receipt and opening of pushes, the process to be followed in order to accomplish the same has been mentioned below.

2.1 Push Open

To track the click of push notifications for your application , it is required to attach the below code.

a. In Objective C

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
	TargetActClient *tc = [TargetActClient sharedInstance];
	[tc pushOpenedEvent:userInfo];
}

b. In Swift

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
	TargetActClient.sharedInstance()?.pushOpenedEvent(userInfo)
}

2.2 Push Received

In order to track the receipt of pushes , follow the below steps

It is required to enable the app groups in capabilities section for main target as well as extensions. On completion of the previous step, create a group with same name in both extensions and main target. Add the group name in main info.plist. Add the below snippet in Notification Service extension.

gamooga company id

     <key>GamoogaAppGroup</key>
     <string>groupName</string>

a. In Objective C

-(void)didReceiveNotificationRequest:(UNNotificationRequest *)request
withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler
{
	TargetActClient *tc = [TargetActClient sharedInstance];
	[tc pushReceivedEvent: request.content.userInfo];
}

b. In Swift

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) 
{
    TargetActClient.sharedInstance()?.pushReceivedEvent(request.content.userInfo)
}