To make in-app notifications more engaging, you might want to implement your own user experience so that your in-app messaging can blend into the look and feel of your UI.

To do so, override the following callback methods, and return false, which ensures that Sailthru Mobile's interface isn't displayed. At this point you can trigger your own in-app notification interface using the CarnivalMessage object.

//On iOS, using Objective-C

- (BOOL)shouldPresentInAppNotificationForMessage:(CarnivalMessage *)message {	
  // Do something with the message
  
  // Register an impression *if* you are displaying the notification yourself.
  [CarnivalMessageStream registerImpressionWithType:CarnivalImpressionTypeInAppNotificationView forMessage:message];
  return NO;	
}

//Be sure to assign your delegate to CarnivalMessageStream
[CarnivalMessageStream setDelegate:self]
//On iOS, using Swift

func shouldPresentInAppNotificationForMessage(message: CarnivalMessage) -> Bool {
	return false
}

//Be sure to assign your delegate to CarnivalMessageStream
CarnivalMessageStream.setDelegate(self)
//On Android, using Java

Carnival.setOnInAppNotificationDisplayListener(new 
	Carnival.OnInAppNotificationDisplayListener() {
    @Override
    public boolean shouldPresentInAppNotification(Message message) {
      return false;
    }
});
// In Cordova, you can display or hide in-app notifications by using setDisplayInAppNotifications. To display your own notification UX, listen to the 'inappnotification' event.

Carnival.setDisplayInAppNotifications(false);
document.addEventListener('inappnotification', function(message) {
  // Message will contain a JS payload with the message properties.
});

🚧

Not available in Unity and React Native

Due to limitations of current plugin architecture in Unity and React Native, it is not currently possible to override the stock experience for in-app notifications. Rest assured, you can still deliver these notifications, but you won't be able to customize their UX. We hope to bring customization to these platforms in the near future.

Registering an impression event

In order to support impression analytics in your custom in-app notification, you will need to ensure you register an impression event when it is shown.

//On iOS, using Objective-C
 
[CarnivalMessageStream registerImpressionWithType:CarnivalImpressionTypeInAppNotificationView forMessage:message];
//On iOS, using Swift
   CarnivalMessageStream.registerImpressionWithType(CarnivalImpressionType.InAppNotificationView, forMessage: message)
//On Android, using Java

Carnival.registerMessageImpression(message, CarnivalImpressionType.IMPRESSION_TYPE_IN_APP_VIEW);
//On Cordova, using JavaScript

Carnival.registerImpression(Carnival.MessageImpressionType.InAppView, message);
//On Unity, using C#

Carnival.RegisterImpression(message, CarnivalImpressionType.InAppNotificationView);