FIRInAppMessagingRendering.h 16 KB

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