Overview

Skill Level: Any

Prerequisites

Not what you’re looking for? Check out all our available tutorials for mobile app messaging here.

Step-by-step

  1. Removing expired messages

    By default, the SDK does not remove expired messages. This means you will see expired messages until 30 days after the expire date, then they will automatically be purged by the server. This is useful for showing something that may be missed, perhaps by dimming the message or marking it as “expired”.

    Under other circumstances, though, you may want to delete all expired messages and prevent them from being presented at all.

    Xamarin does not have a clear expired messages method exposed to C# developers, however if you do not wish to show expired messages, modify the code in InboxPage.xaml.cs in the SyncMessages method.

  2. Changing the Inbox UI to match yours

    The inbox that Acoustic Campaign ships is configurable so that you can have it appear the way you want it. For example, if all your other UI has a font of Times Roman with a foreground color of white and a background color of red, you may want your inbox messages to show up in the list with similar styling.

    Default Template:
    Edit the .xaml files in the Default Inbox Template directory to match the desired style using the Xamarin Forms / standard Microsoft XAML language.

    Post Template:
    Edit the .xaml files in the Post Inbox Template directory to match the desired style using the Xamarin Forms / standard Microsoft XAML language.

  3. Showing a background image rather than setting the color

    Default Template:
    Edit the .xaml files in the Default Inbox Template directory to match the desired style using the Xamarin Forms / standard Microsoft XAML language.

    Post Template:
    Edit the .xaml files in the Post Inbox Template directory to match the desired style using the Xamarin Forms / standard Microsoft XAML language.

  4. Adding a custom field to your messages

    The inbox can have custom fields associated with each message. You can use these fields to include information that is useful to your app but not presented in the inbox itself.

    Any custom fields will simply show up in the Content JObject of the InboxMessage object. All fields, subject, body, preview etc., are “custom” fields. For instance the subject is contained within an embedded JObject within the InboxMessage’s content JObject:

    message.Content["messagePreview"]["subject"].toString();
    

     

    And the html content itself is within a separate embedded JObject within the Content JObject:

    message.Content["messageDetails"]["richContent"].toString();
    

     

    But, the developer could put the custom data anywhere they like, even in the root of the Content JObject:

    message.Content["foo"].toString();
    
  5. Changing the Inbox sort order

    Other than by default, you may want to sort the inbox in a different order. For instance, you might want to sort using a custom field rather than by sendDate.

    The simplest way to change the sort order is to use the OrderBy method of the standard Microsoft LINQ library. However, this does not sort in place.

    Messages = new ObservableCollection<InboxMessage>( Messages.OrderBy(i => i.Content["customField"]) );
    
  6. Inbox with different behaviors depending on different kinds of messages received

    To take different behaviors based on the kinds of inbox messages received (e.g., play a sound when special offers are opened but not regular messages), you can override onCreate of InboxMessageDisplayActivity like this:

    There is not a Xamarin Forms prebuilt way to play a sound, so to accomplish this, you will either have to find a plugin, or write a cross platform dependency service. The concept will be the same.

    InboxMessagePage.xaml.cs

    
    
    public InboxMessagePage (InboxMessage message, InboxPage inbox)
    {
    if(message.Content["sound"] != null) {
    MediaPlayer(message.Content["sound"].toString() );
    }
    }
    

Expected outcome

Need more help? Check out all of our available tutorials for mobile app messaging here.

 

Join The Discussion

Your email address will not be published. Required fields are marked *