Customizing Full Screen Messages
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 Marigold's interface isn't displayed. At this point you can construct your own full screen message interface using the MARMessage
object in iOS or 'Message' object in Android.
//On iOS, using Objective-C
- (BOOL)shouldPresentMessageDetailForMessage:(MARMessage *)message {
// Do something with the message
return NO;
}
//Be sure to assign your delegate to STMMessageStream
[[MARMessageStream new] setDelegate:self]
// This delegate is called anytime presentMessageDetailForMessage: is called. Alternatively, just present your view controller manually.
//On iOS, using Swift
func shouldPresentMessageDetailForMessage(message: MARMessage) -> Bool {
return false
}
//Be sure to assign your delegate to MARMessageStream
MARMessageStream().setDelegate(self)
// This delegate is called anytime presentMessageDetailForMessage: 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);
new Marigold().setNotificationConfig(config);
//If a push has a Message attached, the message will be added to the Intent's extras under Marigold.EXTRA_PARCELABLE_MESSAGE.
protected void onResume() {
super.onResume();
String messageId = getIntent().getStringExtra(MessageStream.EXTRA_MESSAGE_ID);
new MessageStream().getMessage(messageId, new MessageStream.MessageStreamHandler<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.
//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.
val intent = Intent(applicationContext, MyMessageDetail::class.java)
val requestCode = 123
val config = NotificationConfig()
config.setDefaultContentIntent(intent, requestCode, PendingIntent.FLAG_UPDATE_CURRENT)
Marigold().setNotificationConfig(config)
//If a push has a Message attached, the message will be added to the Intent's extras under Marigold.EXTRA_PARCELABLE_MESSAGE.
override fun onResume() {
super.onResume()
val messageId = intent.getStringExtra(MessageStream.EXTRA_MESSAGE_ID)
MessageStream().getMessage(messageId, object : MessageStreamHandler<Message?> {
fun onSuccess(value: Message) {
message = value
// Do stuff with the message
}
override fun 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.
Not available in React Native or Unity
Due to limitations of current plugin architecture in React Native and Unity, 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 this platform 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
[[MARMessageStream new] registerImpressionWithType:MARImpressionTypeDetailView forMessage:message];
//On iOS, using Swift
MARMessageStream().registerImpressionWithType(MARImpressionType.DetailView, forMessage: message)
//On Android, using Java
new MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_DETAIL_VIEW, message);
//On Android, using Kotlin
MessageStream().registerMessageImpression(ImpressionType.IMPRESSION_TYPE_DETAIL_VIEW, message)
//On React Native, using JavaScript
SailthruMobile.registerImpression(SailthruMobile.MessageImpressionType.DetailView, message);
Updated 6 months ago