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 and hiding expired messages

    When the server cleans up the messages it marks them as deleted, and only removes them from it’s storage after that deleted flag is synced to the device. When the device is syncing with the server, it will pick up these deleted flags and remove the messages from it’s local store even without calling the clearExpiredMessages method.

    Users will see expired messages for 30 days after the expiration date, and then these messages are automatically purged by the server. This is useful for showing users what they missed (perhaps by dimming the message or marking it as “expired”).

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

    To delete all expired messages add the following in the app startup code:

    [MCEInboxDatabase.sharedInstance clearExpiredMessages]
    

     

    To hide expired messages from a user, uncomment the code in MCEInboxDefaultTemplate.m shouldDisplayInboxMessage:

    if([inboxMessage isExpired]) {
      return FALSE;
    }
    
  2. Modifying inbox templates

    Adjusting the look and feel of the inbox templates:

    The inbox we ship is configurable so that you can have it appear the way you want it. Suppose your other UI uses the Times Roman font with a white foreground color and a red background color. You may want your inbox messages to show up in the list with similar styling.

    • In the Default template edit the .xib files in the Default Template Handler directory to match the desired style using the Interface Builder GUI.
    • In the Post template edit the .xib files in the Post Template directory to match the desired style using the Interface Builder GUI.

    Changing the “container” for inbox messages:

    The MCEInboxTableViewController can be adjusted to look how you wish. Both the container and the inbox templates are adjusted using a combination of adjusting the xib/storyboard as well as adjusting the code.

  3. Show a background image rather than setting the color

    To use an image as your background instead of a color:

    • In the Default Template Handler directory, edit the .xib files to match the desired style using the Interface Builder GUI.

    or

    • In the Post template directory edit the .xib files to match the desired style using the Interface Builder GUI.
  4. 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 standard NSArray sorting methodologies. 

    Using a descriptor:
    [allMessages sortUsingDescriptors:@[ [NSSortDescriptor sortDescriptorWithKey: @”customObject.customField” ascending: self.ascending]]];

     

    Using a custom function:

    NSInteger intSort(MCEInboxMessage * message1, MCEInboxMessage * message2, void *context)
    {
        int v1 = message1.content[@"customObject"][@"customField"]
        int v2 = message2.content[@"customObject"][@"customField"]
        if (v1 < v2)
            return NSOrderedAscending;
        else if (v1 > v2)
            return NSOrderedDescending;
        else
            return NSOrderedSame;
    }
    
    
    NSArray * sortedMessages = [allMessages sortedArrayUsingFunction: intSort context:NULL];
    
  5. Inbox with different behaviors depending on different kinds of messages received

    To set different behaviors based on the kinds of inbox messages received (e.g., play a sound when special offers are opened but not regular messages):

    To designate particular sounds for specific messages, for example, add a custom field to the inbox message itself. The best place to act on that custom field would be in the presentation layer for the specific template that will be used. If one were using a default template and wanting to play a sound when the message was opened, a custom field could be added called “sound”. Then, leave it blank or do not include it if no sound is to be played and specify a filename when a sound should be played:

    MCEInboxDefaultTemplateDisplay.m:
    
    
    -(void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    if(self.inboxMessage && self.inboxMessage.content["sound"]) {
    NSString * name = self.inboxMessage.content["sound"];
    [[NSSound soundNamed:  name] play];
    }
    }
    

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 *