Implement In-App Messaging on iOS
To use certain in-app messaging features, such as button actions, some SDK configurations are needed. The following sections describe these configurations.
To enable and configure In-App Messaging, extend the initialization code described in the Configure the SDK section. The code example shows how to enable the In-App module for version 11 of the iOS SDK.
The SDK handles actions for Notification Settings and Location Settings, while actions for Web URL and App URL require that you implement URL handling.
To control aspects of message display and to get information about the in-app message display lifecycle, use the SDK’s optional delegate functionality.
To make your application a delegate of the SDK’s in-app messaging functionality, use setEventDelegate, as shown in these examples.
This code example shows how to set the event delegate using version 11 of the SDK.
This code example shows how to set the event delegate using version 10 of the SDK.
For version 8.1 of the SDK, use this code.
For version 8.0 of the SDK, use this code.
For version 7 of the SDK, use this code.
The didShow and didClose delegate methods help ensure that you can appropriately manage your app’s view state. In-app messages are shown as the top view controller in your app’s hierarchy. Your application must be able to respond to a view appearing or disappearing.
For version 11.0, use these methods:
For version 10.0 or lower, use these methods:
You can delay or prevent an in-app message’s display using the shouldShow method. For example, you can choose to prevent an in-app message from displaying during the loading process, sign-in flow, and other situations. To prevent or delay message display, set the shouldShow method to return false.
In version 11.0, the message ID is accessed directly via the InAppMessageDetails object within the delegate, and the display is triggered through the InAppMessagingFeature module. Use these methods:
message.id(property of InAppMessageDetails)showInAppMessage
Furthermore, you can capture in-app message data and use it for displaying the specific message at a later time. For example, you can present the message after an end user has successfully signed in. To present the message later in version 10.0 of the SDK, use these methods:
sfmc_messageIdForMessagesfmc_showInAppMessage
This code example shows how to present the message later using version 10 of the SDK.
For version 8.1 of the SDK, use this code.
For version 8.0 of the SDK, use this code.
For version 7 of the SDK, use this code.
By default, in-app messages use your device’s system font. However, you can override the default font face to customize the appearance of an in-app message’s title, body, button, and tertiary text labels.
You can’t change the font size because it’s defined by the design of the message.
To set the display font, use the setInAppMessageFont method to pass the SDK a valid font name for the device’s installed fonts, or your app’s custom fonts.
For version 8.1 of the SDK, use this code.
For version 8.0 of the SDK, use this code.
For version 7 of the SDK, use this code.
If the font is invalid, the SDK returns false and reverts to using the system font.
When a Push Primer is displayed and the user taps the permission button, the SDK triggers the standard iOS notification authorization request.
To customize which permissions are requested (such as alerts, sounds, or badges), use the setNotificationAuthorizationOptions method during SDK initialization.
:::
note If you do not explicitly configure these options, the SDK defaults to requesting .alert, .sound, and .badge.
:::
The code example shows how to configure push permission authorization for version 11 of the iOS SDK.