Integrate your app with Kochava’s Push Notifications Service.
Overview
The following builds upon Apple’s remote notifications capability, as outlined here. You can use Kochava’s Push Notifications Service to send remote notifications to your apps, as well as track app uninstalls and other analytics.
Integration
The following assumes that you have already integrated the Kochava iOS or tvOS SDK. For more information see iOS/tvOS – SDK Integration.
- Add the Remote Notifications Device Token.
-
1234func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){KVAPushNotificationsToken.add(withData: deviceToken)}
-
1234- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{[KVAPushNotificationsToken addWithData:deviceToken];}
-
1234func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){KochavaTracker.shared.addRemoteNotificationsDeviceToken(deviceToken)}
-
1234- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{[KochavaTracker.shared addRemoteNotificationsDeviceToken:deviceToken];}
- Send Push Opened Events.
12345678910@available(iOS 10.0, tvOS 10.0, watchOS 3.0, *)func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void){// KVAEvent// ⓘ Create and send for .pushOpenedlet event = KVAEvent(type: .pushOpened)event.payloadDictionary = response.notification.request.content.userInfoevent.actionString = response.actionIdentifierevent.send()}-
123456789- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{// KVAEvent// ⓘ Create and send for .pushOpenedKVAEvent *event = [KVAEvent eventWithType:KVAEventType.pushOpened];event.payloadDictionary = response.notification.request.content.userInfo;event.actionString = response.actionIdentifier;[event send];}
-
123456789func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool{if #available(iOS 10.0, tvOS 10.0, watchOS 3.0, *){UNUserNotificationCenter.current().delegate = self}return true}1234567891011121314@available(iOS 10.0, tvOS 10.0, watchOS 3.0, *)func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void){// KochavaEvent// ... create and send for .pushOpenedif let event = KochavaEvent(eventTypeEnum: .pushOpened){event.payloadDictionary = response.notification.request.content.userInfoevent.actionString = response.actionIdentifierKochavaTracker.shared.send(event)}}
-
123456789- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{if (@available(iOS 10.0, tvOS 10.0, watchOS 3.0, *)){UNUserNotificationCenter.currentNotificationCenter.delegate = self;}return YES;}12345678910111213- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{// KochavaEvent// ... create and send for .pushOpenedKochavaEvent *event = [KochavaEvent eventWithEventTypeEnum:KochavaEventTypeEnumPushOpened];if (event != nil){event.payloadDictionary = response.notification.request.content.userInfo;event.actionString = response.actionIdentifier;[KochavaTracker.shared sendEvent:event];}}
- Activate Push Notifications with Kochava.
- Optionally clear your application icon badge number. For more information, refer to our Engagement Overview documentation
For your instance of class KochavaTracker, call instance method addRemoteNotificationsDeviceToken(_:) and pass the device token provided by the operating system.
When your app is opened through a push notification, you may create and send an instance of class KochavaEvent to track that this occurred. The event type should be of type .pushOpened. The event payload should contain the response.notification.request.content.userInfo, so that the event can be attributed to a campaign. It is also recommended that you pass the response.actionIdentifier, so that you may track what action the user selected.
Push Notifications must be activated on your Kochava dashboard. From there you may also configure push notification campaigns.
On your Kochava dashboard you may indicate that you want the application icon badge number set when push notifications are sent. If you enable this option you should be prepared to clear your badge number when your application becomes active, or at some other appropriate time. For more information see instance property applicationIconBadgeNumber.