Manual Integraton

Token Handling

Some third party libraries and frameworks can interfere with the Sailthru Mobile SDK's ability to collect push tokens and to handle incoming notifications. If devices are registering with Sailthru Mobile, but without push tokens, you may need to manually forward notifications and device tokens to the Sailthru Mobile iOS SDK.

To do this, you will need to override a few delegate methods on your application delegate.

In application:didRegisterForRemoteNotificationsWithDeviceToken: call the setDeviceTokenInBackground class method on Carnival:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  // Forward the device token data to the Carnival iOS SDK
  [Carnival setDeviceTokenInBackground:deviceToken];
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
  // Forward the device token data to the Carnival iOS SDK
  Carnival.setDeviceTokenInBackground(deviceToken)
}

Notification Handling

To forward notifications to the Sailthru Mobile iOS SDK call the handleNotification: method on Sailthru Mobile with the notification received from application:didReceiveRemoteNotification: and applicationDidReceiveRemoteNotification:fetchCompletionHandler: where appropriate:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  {
	  // Forward the notification's userInfo to the Carnival iOS SDK
	  [Carnival handleNotification:userInfo];
  }

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {
  // Forward the notification's userInfo to the Carnival iOS SDK
  [Carnival handleNotification:userInfo];
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
	// Forward the notification's userInfo to the Carnival iOS SDK
  Carnival.handleNotification(userInfo)
}
    
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

	// Forward the notification's userInfo to the Carnival iOS SDK
  Carnival.handleNotification(userInfo)
}

Foreground Presentation

As of iOS 10, notifications may appear inside the app while the app is open. By default, the Sailthru Mobile SDK hides these, and when In App Messages are associated, a roll-down In App Notification for those are shown. You can override this behaviour by conforming an object UNUserNotificationCenterDelegate and implementing userNotificationCenter:willPresentNotification:. See an example below.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .badge, .sound])
}