FIRInAppMessagingRendering.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <TargetConditionals.h>
  17. #if TARGET_OS_IOS
  18. #import <UIKit/UIKit.h>
  19. NS_ASSUME_NONNULL_BEGIN
  20. /// The type and UI style of an in-app message.
  21. typedef NS_ENUM(NSInteger, FIRInAppMessagingDisplayMessageType) {
  22. /// Modal style.
  23. FIRInAppMessagingDisplayMessageTypeModal,
  24. /// Banner style.
  25. FIRInAppMessagingDisplayMessageTypeBanner,
  26. /// Image-only style.
  27. FIRInAppMessagingDisplayMessageTypeImageOnly,
  28. /// Card style.
  29. FIRInAppMessagingDisplayMessageTypeCard
  30. };
  31. /// Represents how an in-app message should be triggered to appear.
  32. typedef NS_ENUM(NSInteger, FIRInAppMessagingDisplayTriggerType) {
  33. /// Triggered on app foreground.
  34. FIRInAppMessagingDisplayTriggerTypeOnAppForeground,
  35. /// Triggered from an analytics event being fired.
  36. FIRInAppMessagingDisplayTriggerTypeOnAnalyticsEvent
  37. };
  38. /** Contains the display information for an action button.
  39. */
  40. NS_SWIFT_NAME(InAppMessagingActionButton)
  41. @interface FIRInAppMessagingActionButton : NSObject
  42. /**
  43. * Gets the text string for the button
  44. */
  45. @property(nonatomic, nonnull, copy, readonly) NSString *buttonText;
  46. /**
  47. * Gets the button's text color.
  48. */
  49. @property(nonatomic, copy, nonnull, readonly) UIColor *buttonTextColor;
  50. /**
  51. * Gets the button's background color
  52. */
  53. @property(nonatomic, copy, nonnull, readonly) UIColor *buttonBackgroundColor;
  54. /// Unavailable.
  55. - (instancetype)init NS_UNAVAILABLE;
  56. @end
  57. /** Contain display data for an image for a fiam message.
  58. */
  59. NS_SWIFT_NAME(InAppMessagingImageData)
  60. @interface FIRInAppMessagingImageData : NSObject
  61. /**
  62. * Gets the image URL from image data.
  63. */
  64. @property(nonatomic, nonnull, copy, readonly) NSString *imageURL;
  65. /**
  66. * Gets the downloaded image data. It can be null if headless component fails to load it.
  67. */
  68. @property(nonatomic, readonly, nullable) NSData *imageRawData;
  69. /// Unavailable.
  70. - (instancetype)init NS_UNAVAILABLE;
  71. @end
  72. /** Defines the metadata for the campaign to which a FIAM message belongs.
  73. */
  74. NS_SWIFT_NAME(InAppMessagingCampaignInfo)
  75. @interface FIRInAppMessagingCampaignInfo : NSObject
  76. /**
  77. * Identifier for the campaign for this message.
  78. */
  79. @property(nonatomic, nonnull, copy, readonly) NSString *messageID;
  80. /**
  81. * The name of this campaign, as defined in the console on campaign creation.
  82. */
  83. @property(nonatomic, nonnull, copy, readonly) NSString *campaignName;
  84. /**
  85. * Whether or not this message is being rendered in Test On Device mode.
  86. */
  87. @property(nonatomic, readonly) BOOL renderAsTestMessage;
  88. /// Unavailable.
  89. - (instancetype)init NS_UNAVAILABLE;
  90. @end
  91. /** Defines the metadata for a FIAM action.
  92. */
  93. NS_SWIFT_NAME(InAppMessagingAction)
  94. @interface FIRInAppMessagingAction : NSObject
  95. /**
  96. * The text of the action button, if applicable.
  97. */
  98. @property(nonatomic, nullable, copy, readonly) NSString *actionText;
  99. /**
  100. * The URL to follow if the action is clicked.
  101. */
  102. @property(nonatomic, nullable, copy, readonly) NSURL *actionURL;
  103. /// Unavailable.
  104. - (instancetype)init NS_UNAVAILABLE;
  105. /// This class should only be initialized from a custom in-app message UI component implementation.
  106. - (instancetype)initWithActionText:(nullable NSString *)actionText
  107. actionURL:(nullable NSURL *)actionURL;
  108. @end
  109. /**
  110. * Base class representing a FIAM message to be displayed. Don't create instance
  111. * of this class directly. Instantiate one of its subclasses instead.
  112. */
  113. NS_SWIFT_NAME(InAppMessagingDisplayMessage)
  114. @interface FIRInAppMessagingDisplayMessage : NSObject
  115. /**
  116. * Metadata for the campaign to which this message belongs.
  117. */
  118. @property(nonatomic, copy, nonnull, readonly) FIRInAppMessagingCampaignInfo *campaignInfo;
  119. /**
  120. * The type and UI style of this message.
  121. */
  122. @property(nonatomic, readonly) FIRInAppMessagingDisplayMessageType type;
  123. /**
  124. * How this message should be triggered.
  125. */
  126. @property(nonatomic, readonly) FIRInAppMessagingDisplayTriggerType triggerType;
  127. /**
  128. * Extra key-value dictionary data that can be sent along with the message
  129. */
  130. @property(nonatomic, nullable, readonly) NSDictionary *appData;
  131. /// Unavailable.
  132. - (instancetype)init NS_UNAVAILABLE;
  133. @end
  134. NS_SWIFT_NAME(InAppMessagingCardDisplay)
  135. @interface FIRInAppMessagingCardDisplay : FIRInAppMessagingDisplayMessage
  136. /**
  137. * Gets the title text for a card FIAM message.
  138. */
  139. @property(nonatomic, nonnull, copy, readonly) NSString *title;
  140. /**
  141. * Gets the body text for a card FIAM message.
  142. */
  143. @property(nonatomic, nullable, copy, readonly) NSString *body;
  144. /**
  145. * Gets the color for text in card FIAM message. It applies to both title and body text.
  146. */
  147. @property(nonatomic, copy, nonnull, readonly) UIColor *textColor;
  148. /**
  149. * Image data for the supplied portrait image for a card FIAM messasge.
  150. */
  151. @property(nonatomic, nonnull, copy, readonly) FIRInAppMessagingImageData *portraitImageData;
  152. /**
  153. * Image data for the supplied landscape image for a card FIAM message.
  154. */
  155. @property(nonatomic, nullable, copy, readonly) FIRInAppMessagingImageData *landscapeImageData;
  156. /**
  157. * The background color for a card FIAM message.
  158. */
  159. @property(nonatomic, copy, nonnull, readonly) UIColor *displayBackgroundColor;
  160. /**
  161. * Metadata for a card FIAM message's primary action button.
  162. */
  163. @property(nonatomic, nonnull, readonly) FIRInAppMessagingActionButton *primaryActionButton;
  164. /**
  165. * The action URL for a card FIAM message's primary action button.
  166. */
  167. @property(nonatomic, nullable, readonly) NSURL *primaryActionURL;
  168. /**
  169. * Metadata for a card FIAM message's secondary action button.
  170. */
  171. @property(nonatomic, nullable, readonly) FIRInAppMessagingActionButton *secondaryActionButton;
  172. /**
  173. * The action URL for a card FIAM message's secondary action button.
  174. */
  175. @property(nonatomic, nullable, readonly) NSURL *secondaryActionURL;
  176. /// Unavailable.
  177. - (instancetype)init NS_UNAVAILABLE;
  178. @end
  179. /** Class for defining a modal message for display.
  180. */
  181. NS_SWIFT_NAME(InAppMessagingModalDisplay)
  182. @interface FIRInAppMessagingModalDisplay : FIRInAppMessagingDisplayMessage
  183. /**
  184. * Gets the title for a modal fiam message.
  185. */
  186. @property(nonatomic, nonnull, copy, readonly) NSString *title;
  187. /**
  188. * Gets the image data for a modal fiam message.
  189. */
  190. @property(nonatomic, nullable, copy, readonly) FIRInAppMessagingImageData *imageData;
  191. /**
  192. * Gets the body text for a modal fiam message.
  193. */
  194. @property(nonatomic, nullable, copy, readonly) NSString *bodyText;
  195. /**
  196. * Gets the action button metadata for a modal fiam message.
  197. */
  198. @property(nonatomic, nullable, readonly) FIRInAppMessagingActionButton *actionButton;
  199. /**
  200. * Gets the action URL for a modal fiam message.
  201. */
  202. @property(nonatomic, nullable, readonly) NSURL *actionURL;
  203. /**
  204. * Gets the background color for a modal fiam message.
  205. */
  206. @property(nonatomic, copy, nonnull, readonly) UIColor *displayBackgroundColor;
  207. /**
  208. * Gets the color for text in modal fiam message. It would apply to both title and body text.
  209. */
  210. @property(nonatomic, copy, nonnull, readonly) UIColor *textColor;
  211. /// Unavailable.
  212. - (instancetype)init NS_UNAVAILABLE;
  213. @end
  214. /** Class for defining a banner message for display.
  215. */
  216. NS_SWIFT_NAME(InAppMessagingBannerDisplay)
  217. @interface FIRInAppMessagingBannerDisplay : FIRInAppMessagingDisplayMessage
  218. /**
  219. * Gets the title of a banner message.
  220. */
  221. @property(nonatomic, nonnull, copy, readonly) NSString *title;
  222. /**
  223. * Gets the image data for a banner message.
  224. */
  225. @property(nonatomic, nullable, copy, readonly) FIRInAppMessagingImageData *imageData;
  226. /**
  227. * Gets the body text for a banner message.
  228. */
  229. @property(nonatomic, nullable, copy, readonly) NSString *bodyText;
  230. /**
  231. * Gets banner's background color
  232. */
  233. @property(nonatomic, copy, nonnull, readonly) UIColor *displayBackgroundColor;
  234. /**
  235. * Gets the color for text in banner fiam message. It would apply to both title and body text.
  236. */
  237. @property(nonatomic, copy, nonnull, readonly) UIColor *textColor;
  238. /**
  239. * Gets the action URL for a banner fiam message.
  240. */
  241. @property(nonatomic, nullable, readonly) NSURL *actionURL;
  242. /// Unavailable.
  243. - (instancetype)init NS_UNAVAILABLE;
  244. @end
  245. /** Class for defining a image-only message for display.
  246. */
  247. NS_SWIFT_NAME(InAppMessagingImageOnlyDisplay)
  248. @interface FIRInAppMessagingImageOnlyDisplay : FIRInAppMessagingDisplayMessage
  249. /**
  250. * Gets the image for this message
  251. */
  252. @property(nonatomic, nonnull, copy, readonly) FIRInAppMessagingImageData *imageData;
  253. /**
  254. * Gets the action URL for an image-only fiam message.
  255. */
  256. @property(nonatomic, nullable, readonly) NSURL *actionURL;
  257. /// Unavailable.
  258. - (instancetype)init NS_UNAVAILABLE;
  259. @end
  260. /// The way that an in-app message was dismissed.
  261. typedef NS_ENUM(NSInteger, FIRInAppMessagingDismissType) {
  262. /// Message was swiped away (only valid for banner messages).
  263. FIRInAppMessagingDismissTypeUserSwipe,
  264. /// The user tapped a button to close this message.
  265. FIRInAppMessagingDismissTypeUserTapClose,
  266. /// The message was automatically dismissed (only valid for banner messages).
  267. FIRInAppMessagingDismissTypeAuto,
  268. /// Dismiss method unknown.
  269. FIRInAppMessagingDismissUnspecified,
  270. };
  271. /// Error code for an in-app message that failed to display.
  272. typedef NS_ENUM(NSInteger, FIAMDisplayRenderErrorType) {
  273. /// The image data for this in-app message is invalid.
  274. FIAMDisplayRenderErrorTypeImageDataInvalid,
  275. /// Unexpected error.
  276. FIAMDisplayRenderErrorTypeUnspecifiedError,
  277. };
  278. /**
  279. * A protocol defining those callbacks to be triggered by the message display component
  280. * under appropriate conditions.
  281. */
  282. NS_SWIFT_NAME(InAppMessagingDisplayDelegate)
  283. @protocol FIRInAppMessagingDisplayDelegate <NSObject>
  284. @optional
  285. /**
  286. * Called when the message is dismissed. Should be called from main thread.
  287. * @param inAppMessage the message that was dismissed.
  288. * @param dismissType specifies how the message is closed.
  289. */
  290. - (void)messageDismissed:(FIRInAppMessagingDisplayMessage *)inAppMessage
  291. dismissType:(FIRInAppMessagingDismissType)dismissType;
  292. /**
  293. * Called when the message's action button is followed by the user.
  294. * @param inAppMessage the message that was clicked.
  295. * @param action contains the text and URL for the action that was clicked.
  296. */
  297. - (void)messageClicked:(FIRInAppMessagingDisplayMessage *)inAppMessage
  298. withAction:(FIRInAppMessagingAction *)action;
  299. /**
  300. * Use this to mark a message as having gone through enough impression so that
  301. * headless component can make appropriate impression tracking for it.
  302. *
  303. * Calling this is optional.
  304. *
  305. * When messageDismissedWithType: or messageClicked is
  306. * triggered, the message would be marked as having a valid impression implicitly.
  307. * Use impressionDetected if the UI implementation would like to mark valid
  308. * impression in additional cases. One example is that the message is displayed for
  309. * N seconds and then the app is killed by the user. Neither
  310. * onMessageDismissedWithType or onMessageClicked would be triggered
  311. * in this case. But if the app regards this as a valid impression and does not
  312. * want the user to see the same message again, call impressionDetected to mark
  313. * a valid impression.
  314. * @param inAppMessage the message for which an impression was detected.
  315. */
  316. - (void)impressionDetectedForMessage:(FIRInAppMessagingDisplayMessage *)inAppMessage;
  317. /**
  318. * Called when the display component could not render the message due to various reason.
  319. * It's essential for display component to call this when error does arise. On seeing
  320. * this, the headless component of fiam would assume that a prior attempt to render a
  321. * message has finished and therefore it's ready to render a new one when conditions are
  322. * met. Missing this callback in failed rendering attempt would make headless
  323. * component think a fiam message is still being rendered and therefore suppress any
  324. * future message rendering.
  325. * @param inAppMessage the message that encountered a display error.
  326. */
  327. - (void)displayErrorForMessage:(FIRInAppMessagingDisplayMessage *)inAppMessage
  328. error:(NSError *)error;
  329. @end
  330. /**
  331. * The protocol that a FIAM display component must implement.
  332. */
  333. NS_SWIFT_NAME(InAppMessagingDisplay)
  334. @protocol FIRInAppMessagingDisplay
  335. /**
  336. * Method for rendering a specified message on client side. Invoked on a background thread.
  337. * @param messageForDisplay the message object. It would be of one of the three message
  338. * types at runtime.
  339. * @param displayDelegate the callback object used to trigger notifications about certain
  340. * conditions related to message rendering.
  341. */
  342. - (void)displayMessage:(FIRInAppMessagingDisplayMessage *)messageForDisplay
  343. displayDelegate:(id<FIRInAppMessagingDisplayDelegate>)displayDelegate;
  344. @end
  345. NS_ASSUME_NONNULL_END
  346. #endif // TARGET_OS_IOS