// In AppDelegate.swift// Register the delegate with the InAppMessaging instanceletmyFiamDelegate=CardActionFiamDelegate()InAppMessaging.inAppMessaging().delegate=myFiamDelegate;
classCardActionDelegate:NSObject,InAppMessagingDisplayDelegate{funcmessageClicked(_inAppMessage:InAppMessagingDisplayMessage){// Get data bundle from the inapp messageletappData=inAppMessage.appData// ...}}
// Only needed if FirebaseInAppMessagingAutomaticDataCollectionEnabled is set to NO// in Info.plist[FIRInAppMessaginginAppMessaging].automaticDataCollectionEnabled=YES;
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["\u003cbr /\u003e\n\niOS+ Android Flutter \n\n\u003cbr /\u003e\n\nWith little to no coding effort, Firebase In-App Messaging allows you to create,\nconfigure and target rich user interactions, leveraging\nthe capabilities of Google Analytics out of the box\nto tie messaging events to actual user characteristics, activities, and choices.\nWith some additional Firebase In-App Messaging SDK integration, you can tailor\nthe behavior of in-app messages even further, responding when users interact\nwith messages, triggering message events outside the Analytics\nframework, and allowing users to control sharing of their personal data related\nto messaging interactions.\n\nRespond when users interact with in-app messages\n\nWith actions you can use your in-app messages to direct users to a\nwebsite or a specific screen in your app.\n\nYour code can respond to basic interactions (clicks and dismissals), to\nimpressions (verified views of your messages), and to display errors logged and\nconfirmed by the SDK. For example, when your message is composed as a Card\nmodal, you might want to track and follow-up on which of two URLs the user\nclicked on the Card.\n\nImplement a DisplayDelegate to handle Card interactions\n\nYou can register an in-app messaging display delegate that will be called\nwhenever there is any interaction with an in-app message. To do this, implement\na class per the `InAppMessagingDisplayDelegate` protocol and set it as the\ndelegate property on the `InAppMessaging` instance.\n\nAssuming again that you want to track which link a user clicked on a Card-style\nmessage, define a class that implements the `messageClicked` method per the\n`DisplayDelegate` protocol, thereby providing you access to the\nlink clicked by the user. \n\nSwift\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.\n\nRefer to the Swift [display delegate reference](/docs/reference/swift/firebaseinappmessaging/api/reference/Protocols/InAppMessagingDisplayDelegate) for the set of callback methods that can be implemented and their parameters, including\nInAppMessagingAction. \n\n\n // In CardActionFiamDelegate.swift\n class CardActionFiamDelegate : NSObject, InAppMessagingDisplayDelegate {\n\n func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage) {\n // ...\n }\n\n func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,\n dismissType: InAppMessagingDismissType) {\n // ...\n }\n\n func impressionDetected(for inAppMessage: InAppMessagingDisplayMessage) {\n // ...\n }\n\n func displayError(for inAppMessage: InAppMessagingDisplayMessage, error: Error) {\n // ...\n }\n\n } \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReferenceSwift/CardActionFiamDelegate.swift#L20-L39\n\n\n // In AppDelegate.swift\n // Register the delegate with the InAppMessaging instance\n let myFiamDelegate = CardActionFiamDelegate()\n InAppMessaging.inAppMessaging().delegate = myFiamDelegate; \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReferenceSwift/AppDelegate.swift#L30-L32\n\nObjective-C\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets.\n\nRefer to the Objective-C [display delegate reference](/docs/reference/ios/firebaseinappmessaging/api/reference/Protocols/FIRInAppMessagingDisplayDelegate) for the set of callback methods that can be implemented and their parameters, including\nFIRInAppMessagingDisplayMessage. \n\n\n // In CardActionFiamDelegate.h\n @interface CardActionFiamDelegate : NSObject \u003cFIRInAppMessagingDisplayDelegate\u003e\n @end\n\n // In CardActionFiamDelegate.m\n @implementation CardActionFiamDelegate\n\n - (void)displayErrorForMessage:(nonnull FIRInAppMessagingDisplayMessage *)inAppMessage\n error:(nonnull NSError *)error {\n // ...\n }\n\n - (void)impressionDetectedForMessage:(nonnull FIRInAppMessagingDisplayMessage *)inAppMessage {\n // ...\n }\n\n - (void)messageClicked:(nonnull FIRInAppMessagingDisplayMessage *)inAppMessage {\n // ...\n }\n\n - (void)messageDismissed:(nonnull FIRInAppMessagingDisplayMessage *)inAppMessage\n dismissType:(FIRInAppMessagingDismissType)dismissType {\n // ...\n }\n\n @end \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReference/CardActionFiamDelegate.m#L20-L40\n\n\n // In AppDelegate.m\n CardActionFiamDelegate *myFiamDelegate = [CardActionFiamDelegate new];\n [FIRInAppMessaging inAppMessaging].delegate = myFiamDelegate; \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReference/AppDelegate.m#L35-L36\n\nTrigger in-app messages programmatically\n\nFirebase In-App Messaging by default allows you to trigger in-app messages with\nGoogle Analytics for Firebase events, with no additional integration. You can\nalso manually trigger events programmatically with the Firebase In-App Messaging SDK's\nprogrammatic triggers.\n\nIn the In-App Messaging campaign composer, create a new campaign or select an\nexisting campaign, and in the Scheduling step of the composer workflow, note the\nevent ID of a newly-created or existing messaging event. Once noted, instrument\nyour app to trigger the event by its ID. \n\nSwift\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets. \n\n ...\n // somewhere in the app's code\n InAppMessaging.inAppMessaging().triggerEvent(\"exampleTrigger\");\n\nObjective-C\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets. \n\n ...\n // somewhere in the app's code\n [[FIRInAppMessaging inAppMessaging] triggerEvent:@\"exampleTrigger\"];\n\nUse campaign custom metadata\n\nIn your campaigns, you can specify custom data in a series of key/value pairs.\nWhen users interact with messages, this data is available for you to, for example,\ndisplay a promo code. \n\nSwift\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets. \n\n class CardActionDelegate : NSObject, InAppMessagingDisplayDelegate {\n\n func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage) {\n \t// Get data bundle from the inapp message\n \tlet appData = inAppMessage.appData\n \t// ...\n }\n } \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReferenceSwift/CardActionFiamDelegate.swift#L44-L51\n\nObjective-C\n\n\n**Note:** This product is not available on macOS, Mac Catalyst, App Clip or watchOS targets. \n\n @implementation ExampleCardActionDelegate\n\n - (void)messageClicked:(nonnull FIRInAppMessagingDisplayMessage *)inAppMessage {\n NSDictionary *appData = inAppMessage.appData;\n NSLog(@\"Message data: %@\", appData);\n \t// ...\n }\n\n @end \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReference/CardActionFiamDelegate.m#L48-L56\n\nTemporarily disable in-app messages\n\nBy default, Firebase In-App Messaging renders messages whenever a triggering condition is\nsatisfied, regardless of an app's current state. If you'd like to suppress\nmessage displays for any reason, for example to avoid interrupting a\nsequence of payment processing screens, use the SDK's\n`messageDisplaySuppressed` property as illustrated here in Objective-C: \n\n [FIRInAppMessaging inAppMessaging].messageDisplaySuppressed = YES; \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReference/ViewController.m#L31-L31\n\nSetting the property to `YES` prevents Firebase In-App Messaging from displaying messages,\nwhile `NO` reenables message display. The SDK resets the property to `NO`\non app restart. Suppressed messages are ignored by the SDK. Their trigger\nconditions must be met again while suppression is off, before Firebase In-App Messaging can\ndisplay them.\n\nEnable opt-out message delivery\n\nBy default, Firebase In-App Messaging automatically delivers messages to all app users you target\nin messaging campaigns. To deliver those messages, the Firebase In-App Messaging SDK uses\nFirebase installation IDs to identify each user's app. This means\nthat In-App Messaging has to send client data, linked to the\ninstallation ID, to Firebase servers. If you'd like to give users\nmore control over the data they send, disable automatic data collection and give\nthem a chance to approve data sharing.\n\nTo do that, you have to disable automatic initialization for Firebase In-App Messaging, and\ninitialize the service manually for opt-in users:\n\n1. Turn off automatic initialization with a new key in your `Info.plist` file:\n\n - Key: `FirebaseInAppMessagingAutomaticDataCollectionEnabled`\n - Value: `NO`\n2. Initialize Firebase In-App Messaging for selected users manually:\n\n // Only needed if FirebaseInAppMessagingAutomaticDataCollectionEnabled is set to NO\n // in Info.plist\n [FIRInAppMessaging inAppMessaging].automaticDataCollectionEnabled = YES; \n https://github.com/firebase/snippets-ios/blob/cdce007fedb3bb90dd3a70ce03066178236e1deb/inappmessaging/FIAMReference/FIAMReference/ViewController.m#L37-L39\n\n Once you set `automaticDataCollectionEnabled` to `YES`, the value persists\n through app restarts, overriding the value in your `Info.plist`. If you'd like\n to disable initialization again, for example if a user opts out of\n collection later, set the property to `NO`."]]