Configure Marketing Cloud Engagement
Runtime Toggles
Event Tracking
Update Imports on iOS
Upgrade In-App Messaging on iOS
Handle URLs
Data Protection and Privacy
Changelog
The processes for implementing and customizing in-app messaging have been updated in version 11 of the SDK. To upgrade your app to version 11 of the SDK, first update the initialization code. Then, use these code examples to update the in-app messaging code in your app.
To make your application a delegate of the SDK’s in-app messaging functionality, use setEventDelegate. This code example shows how to set the event delegate using version 11 of the SDK.
1// adhere to the InAppMessageEventDelegate protocol in your class declaration
2class MyViewController: UIViewController, InAppMessageEventDelegate
3...
4// somewhere in your implementation, set your class as the delegate of the SDK for In-App Message events
5// this should be done early in your class’s initialization, if possible
6InAppMessagingFeature.requestSdk { iam in
7 iam?.setEventDelegate(self)
8}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.
1func shouldShow(inAppMessage message: InAppMessageDetails) -> Bool {
2 // using your app's logic, can this message be shown?
3 if (self.messageCanBeShown) {
4 return true
5 }
6 else {
7 // capture the message id in the event
8 self.showMessageId = message.id
9 }
10 return false
11}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)showInAppMessage1// if you've previously captured the messageId, you can show the In-App Message later
2// (for instance, you've returned false from shouldShow(inAppMessage message: InAppMessageDetails) because
3// your UI or application logic couldn’t be interrupted)
4if (self.showMessageId != nil) {
5 InAppMessagingFeature.requestSdk { iam in
6 iam?.showInAppMessage(messageId: self.showMessageId)
7 }
8}Use this code example to customize the font used in an in-app message.
1InAppMessagingFeature.requestSdk { iam in
2 iam?.setInAppMessageFont(name: "Zapfino")
3}