Customizing the user interface

Sometimes, you might want to implement your own user interface for a full screen message that more closely matches the look and feel of your UI.

Override the following callback method, and return false, which ensures that Sailthru Mobile's interface isn't displayed. At this point you can construct your own full screen message interface using the CarnivalMessage object in iOS or 'Message' object in Android.

//On iOS, using Objective-C

- (BOOL)shouldPresentMessageDetailForMessage:(CarnivalMessage *)message {   
  // Do something with the message
  return NO;    
}

//Be sure to assign your delegate to CarnivalMessageStream
[CarnivalMessageStream setDelegate:self]


// This delegate is called anytime [CarnivalMessageStream presentMessageDetailForMessage:message] is called. Alternatively, just present your view controller manually.
//On iOS, using Swift

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

//Be sure to assign your delegate to CarnivalMessageStream
CarnivalMessageStream.setDelegate(self)

// This delegate is called anytime [CarnivalMessageStream presentMessageDetailForMessage:message] is called. Alternatively, just present your view controller manually.
//For setting the Intent fired when a notification is interacted with, use NotificationConfig#setDefaultContentIntent(Intent, int, int) so that push payload data can be added to the PendingIntent when the Notification is built.

Intent intent = new Intent(getApplicationContext(), MyMessageDetail.class);
int requestCode = 123;

NotificationConfig config = new NotificationConfig();
config.setDefaultContentIntent(intent, requestCode, PendingIntent.FLAG_UPDATE_CURRENT);
Carnival.setNotificationConfig(config);

//If a push has a Message attached, the message will be added to the Intent's extras under Carnival.EXTRA_PARCELABLE_MESSAGE.

protected void onResume() {
    super.onResume();

    String messageId = getIntent().getStringExtra(Carnival.EXTRA_MESSAGE_ID);

    Carnival.getMessage(messageId, new Carnival.CarnivalHandler<Message>() {
        @Override
        public void onSuccess(Message value) {
            message = value;
            // Do stuff with the message
        }

        @Override
        public void onFailure(Error error) {
            Log.e(TAG, "Failed to load message: " + error);
        }
    });
}


// For setting the Intent fired when a message in a message stream is tapped, intialise this as you normally would any other.
// Retrieve the message stream and store it in memory.
// If you are building a message stream, you can reuse the result from a previous
// call to Carnival.messages().
var messages = {};
Carnival.messages(
  function callback(data) {
    // 'data' contains an array of messages
    for (var i in data) {
      var message = data[i];
      messages[message.id] = message;
    }
  },
  function errorHandler(err) {
    console.error('An error occurred: ' + err);
  }
);

// In your message stream logic, add a listener to register 
// an impression, then open your custom message view
messageListItem.addEventListener('click', function() {
  // First, register an impression
  var messageId = this.getAttribute('data-message-id');
  var message = messages[messageId];
  Carnival.registerImpression(Carnival.MessageImpressionType.DetailView, message);
  
  // Add your logic to display the detail view for this message, 
  // or to deeplink the user to the link URL for this message.
});

🚧

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:CarnivalImpressionTypeDetailView forMessage:message];
//On iOS, using Swift
   CarnivalMessageStream.registerImpressionWithType(CarnivalImpressionType.DetailView, forMessage: message)
//On Android, using Java

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

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

Carnival.RegisterImpression(message, CarnivalImpressionType.DetailView);