如何在iOS应用中自定义Firebase应用内消息

enxuqcxy  于 2023-06-24  发布在  iOS
关注(0)|答案(2)|浏览(157)

有任何定制应用内消息传递的详细信息吗?我可以在iOS中使用Firebase应用内消息传递来显示一个自定义的弹出窗口吗?
有关于如何定制这个的示例或细节吗?
https://firebase.google.com/docs/in-app-messaging/customize-messages?platform=ios#create_your_own_message_display_library

u2nhd7ah

u2nhd7ah1#

这是我的代码:

class MyInAppMessagingDelegate: NSObject, InAppMessagingDelegate {
func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage, campaignInfo: InAppMessagingCampaignInfo?) {
    // Check if the message is of type InAppMessagingModalDisplay
    guard let modalDisplay = inAppMessage.displayInfo as? InAppMessagingModalDisplay else {
        return
    }
    
    // Check the button ID to perform specific actions
    if inAppMessage.triggerAction.actionButton?.buttonId == "updateButton" {
        // Handle Update button click
        // Add your custom logic here
    } else if inAppMessage.triggerAction.actionButton?.buttonId == "cancelButton" {
        // Handle Cancel button click
        // Add your custom logic here
    }
}

}
你可以尝试两个按钮(更新和取消)

0md85ypi

0md85ypi2#

要自定义应用中消息的显示,您需要实现FIRInAppMessagingDisplayDelegate协议。这允许您为应用内消息提供自定义显示。
以下是如何自定义应用内消息显示的示例:

import FirebaseInAppMessaging

class CustomInAppMessagingDisplayDelegate: NSObject, FIRInAppMessagingDisplayDelegate {
    
    func messageClicked(_ inAppMessage: FIRInAppMessagingDisplayMessage, with action: FIRInAppMessagingAction) {
        // Handle the click action for the In-App message
    }
    
    func messageDismissed(_ inAppMessage: FIRInAppMessagingDisplayMessage, dismissType: FIRInAppMessagingDismissType) {
        // Handle the dismiss action for the In-App message
    }
    
    func messageWillDisplay(_ inAppMessage: FIRInAppMessagingDisplayMessage) {
        // Customize the display of the In-App message
        
        // Access the message components
        let title = inAppMessage.messageContent.title.text
        let subtitle = inAppMessage.messageContent.body.text
        let actionButton1 = inAppMessage.messageContent.actionButton?[0]
        let actionButton2 = inAppMessage.messageContent.actionButton?[1]
        
        // Create a custom popup with the message components
        // Display the popup with the provided title, subtitle, and buttons
    }
    
    func impressionDetected(for inAppMessage: FIRInAppMessagingDisplayMessage) {
        // Track impression events for the In-App message
    }
}

// Register the custom display delegate
FIRInAppMessaging.inAppMessaging().delegate = CustomInAppMessagingDisplayDelegate()

希望这能帮到你

相关问题