In-App Automation

In-App Messages are messages that appear inside of your app, regardless of the opt-in/opt-out status of a user notifications.

Note

This guide applies to in-app messages sent via In-App Automation.

In-app messaging can improve your engagement strategy by providing messages that can be customized to be visually consistent with the the rest of your app. Most customization can be accomplished through the dashboard workflow, however more advanced customization can be obtained by modifying the Urban Airship SDK. This guide outlines how to customize iOS in-app messages.

Feature enablement

Disabling the manager:

[[UAirship inAppMessageManager] setEnabled:false];

The in-app messaging manager can be enabled or disabled. When the manager is disabled it prevents any in-app messages from displaying and any events from counting towards a trigger's goal.

Pausing message display

Pausing the manager:

[[UAirship inAppMessageManager] setPaused:true];

Pausing is simliar to disabling the manager, but messages can continue to be trigged and queued up for display. This is useful for preventing in-app message displays on screens where it would be detrimental to the user experience, such as splash screens, settings screens, or landing pages.

Display interval

Setting the display interval to 10 seconds:

[UAirship inAppMessageManager].displayInterval = 10;

The display interval controls the amount of time to wait before the manager is able to display the next triggered in-app message. The default value is set to 30 seconds but can be adjusted to any amount of time in seconds.

Implementing the UAInAppMessagingDelegate protocol

Example delegate:

-(void)messageWillBeDisplayed:(UAInAppMessage \*)message scheduleID:(NSString \*)scheduleID {
  // Message displayed
}

-(void)messageFinishedDisplaying:(UAInAppMessage \*)message scheduleID:(NSString \*)scheduleID resolution:(UAInAppMessageResolution \*)resolution {
  // Message finished
}

- (UAInAppMessage *)extendMessage:(UAInAppMessage *)message {
    // Can be used to modify the message before it is displayed
    return message;
}

Setting the delegate

[UAirship inAppMessageManager].delegate = automationDelegate;

The UAInAppMessagingDelegate can be implemented to receive callback when a message is displayed, finished displaying, and to modify the message before being displayed.

Fonts

Fonts added to the app bundle are available for use with in-app messaging. To add fonts, please read the The UIKit Custom Fonts Guide.

Customization

In-app messages are fully customizable. Minor modifications can be accomplished by overriding the styles with a plist, but more advanced customizations can employ an adapter for the given message type.

Styles

Plists can be used to modify any of the default message styles that the SDK provides. Each message type can be customized with a different plist:

  • Banner: UAInAppMessageBannerStyle.plist
  • HTML: UAInAppMessageHTMLStyle.plist
  • FullScreen: UAInAppMessageFullScreenStyle.plist
  • Modal: UAInAppMessageModalStyle.plist

Individual messages can be customized by setting a custom factory block on the in-app message which configures a display adapter with the appropriate style:

[[UAirship inAppMessageManager] setFactoryBlock:^id<UAInAppMessageAdapterProtocol> (UAInAppMessage *message) {
    UAInAppMessageHTMLAdapter *adapter = [UAInAppMessageHTMLAdapter adapterForMessage:message];
    adapter.style = [UAInAppMessageHTMLStyle style];
    adapter.style.additionalPadding = [UAPadding paddingWithTop:20 bottom:20 leading:0 trailing:0];
    return adapter;
} forDisplayType:UAInAppMessageDisplayTypeHTML];

Plist values

Banner

  • additionalPadding: Padding. Adds padding around the view.
  • headerStyle: Text Style. Customizes the message's header.
  • bodyStyle: Text Style. Customizes the message's body.
  • mediaStyle: Media Style. Customizes the message's media.
  • buttonStyle: Buttons Style. Customzies the message's buttons.
  • maxWidth: Points. Max width.

FullScreen

  • headerStyle: Text Style. Customizes the banner's header.
  • bodyStyle: Text Style. Customizes the banner's body.
  • mediaStyle: Media Style. Customizes the banner's media.
  • buttonStyle: Buttons Style. Customzies the banner's buttons.
  • dismissIconResource: String. Resource name for a custom dismiss icon.

Modal

  • additionalPadding: Padding. Adds padding around the view.
  • headerStyle: Text Style. Customizes the banner's header.
  • bodyStyle: Text Style. Customizes the banner's body.
  • mediaStyle: Media Style. Customizes the banner's media.
  • buttonStyle: Buttons Style. Customzies the banner's buttons.
  • dismissIconResource: String. Resource name for a custom dismiss icon.
  • maxWidth: Points. Max width.
  • maxHeight: Points. Max height.

HTML

  • additionalPadding: Padding. Adds padding around the view.
  • dismissIconResource: String. Resource name for a custom dismiss icon.
  • maxWidth: Points. Max width.
  • maxHeight: Points. Max height.

Padding

  • top: Points. Top padding.
  • botttom: Points. Bottom padding.
  • leading: Points. Leading padding.
  • trailing: Points. Trailing padding.

Buttons Style

  • additionalPadding: Padding. Adds padding around the button area.
  • buttonHeight: Points. Button height.
  • stackedButtonSpacing: Points. Button spacing in the stacked layout.
  • separatedButtonSpacing: Points. Button spacing in the separated layout.
  • borderWidth: Points. Button's border width.
  • buttonTextStyle: Text Style. Text style for each button.

Text Style

  • additionalPadding: Padding. Adds padding around the view.
  • letterSpacing: Points. Spacing between the letters.
  • lineSpacing: Points. Spacing between lines.

Media Style

  • additionalPadding: Padding. Adds padding around the view.

Custom adapters

Example custom adapter:

\@implementation CustomInAppMessageAdapter

+(instancetype)adapterForMessage:(UAInAppMessage \*)message {
    return [[CustomInAppMessageAdapter alloc] initWithMessage:message];
}

-(instancetype)initWithMessage:(UAInAppMessage \*)message {
    self = [super init];

    if (self) {
        // Initialize the adapter
    }

    return self;
}

-(void)prepare:(void (^)(UAInAppMessagePrepareResult))completionHandler {
    // Download any resources for the in-app message before displaying

    // Call the completion handler with the correct result
    completionHandler(UAInAppMessagePrepareResultSuccess)
}

-(BOOL)isReadyToDisplay {
    // Return ready state
    return true
}

-(void)display:(void (^)(UAInAppMessageResolution \*))completionHandler {
    // Display the in-app message

    // Create a message resolution object corresponding to the correct resolution type
    UAInAppMessageResolution \*messageResolution = [UAInAppMessageResolution messageClickResolution];

    // Call the completion handler with the correct resolution
    completionHandler(messageResolution)
}

@end

Set the factory block on the UAInAppMessageManager instance to provide the new adapter:

[self setFactoryBlock:^id<UAInAppMessageAdapterProtocol> \_Nonnull(UAInAppMessage \* \_Nonnull message) {
    return [CustomInAppMessageAdapter adapterForMessage:message];
} forDisplayType:UAInAppMessageDisplayTypeCustom];

Providing an adapter allows defining the behavior of the custom type or overriding any of the default message types. The adapter will be created by the in-app messaging manager when a message's schedule is triggered. Once created, the adapter will be called to first prepare the in-app message, giving the adapter time to download any resources such as images. After the adapter prepares the message, the adapter will be called to display the message.

After the message is displayed, display must be notified that the message is finished displaying by passing a UAInAppMessageResolution into the display method's completion handler. This will allow for subsequent in-app messages to be displayed.

Standard In-App Messages

Implementing the UALegacyInAppMessageFactoryDelegate protocol - example delegate:

\@implementation MessageFactoryDelegate

+(instancetype)messageFactoryDelegate {
    return [[MessageFactoryDelegate alloc] init];
}

-(instancetype)init {
    self = [super init];

    if (self) {
       // Initialize delegate
        [UAirship legacyInAppMessaging].factoryDelegate = self;
    }

    return self;
}

-(UAInAppMessageScheduleInfo \*)scheduleInfoForMessage:(UALegacyInAppMessage \*)message {
    // Provide any changes to the builder
}

\@end

Standard in-app messages delivered through push messages are managed by the legacy in-app message manager. The UALegacyInAppMessageFactoryDelegate provides the requisite functionality for mapping standard messages onto in-app message schedules.

For more information on how to customize this conversion process, see the In-App Messages Migration guide.