Configure Marketing Cloud Engagement
Runtime Toggles
Set the Event Delegate
Track View States
Prevent or Delay Display
Customize Fonts
Configure Push Permission Authorization
Event Tracking
Handle URLs
Data Protection and Privacy
Changelog
Delay or prevent the display of an in-app message by 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}You can capture in-app message data and use it to display the message later. For example, you can present the message after the user successfully signs in.
Use this code to show a captured message later in version 11 of the SDK for iOS.
Access the message ID in the InAppMessageDetails object within the delegate. Trigger the display through the InAppMessagingFeature module by using 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 to show a captured message later in version 10 of the SDK for iOS.
Use these methods:
sfmc_messageIdForMessagesfmc_showInAppMessage1// If you previously captured the messageId, you can show the In-App Message
2// later (for example, if you returned false from sfmc_shouldShowInAppMessage()
3// because your UI or app logic couldn't be interrupted).
4if (self.showMessageId != nil) {
5 MarketingCloudSdk.requestSdk { mc in
6 mc?.showInAppMessage(messageId: self.showMessageId)
7 }
8}Use this code to show a captured message later in version 8.1 of the SDK for iOS.
1// If you previously captured the messageId, you can show the In-App Message
2// later (for example, if you returned false from sfmc_shouldShowInAppMessage()
3// because your UI or app logic couldn't be interrupted).
4if (self.showMessageId != nil) {
5 SFMCSdk.requestPushSdk { mp in
6 mp.showInAppMessage(messageId: self.showMessageId)
7 }
8}Use this code to show a captured message later in version 8.0 of the SDK for iOS.
1// If you previously captured the messageId, you can show the In-App Message
2// later (for example, if you returned false from sfmc_shouldShowInAppMessage()
3// because your UI or app logic couldn't be interrupted).
4// Make sure the SDK is operational
5if (self.showMessageId != nil) {
6 SFMCSdk.mp.showInAppMessage(messageId: self.showMessageId)
7}Use this code to show a captured message later in version 7 of the SDK for iOS.
1// if you've previously captured the messageId, you can show the In-App Message later
2// (for instance, you've returned false from sfmc_shouldShowInAppMessage() because
3// your UI or application logic couldn't be interrupted)
4if (self.showMessageId != nil) {
5 MarketingCloudSDK.sharedInstance().sfmc_show(inAppMessage: self.showMessageId)
6}