FIRInAppMessagingRendering.h 16 KB

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