FIRInAppMessagingRenderingDataClasses.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 <Foundation/Foundation.h>
  17. #import "FIRInAppMessagingRendering.h"
  18. @implementation FIRInAppMessagingDisplayMessage
  19. - (instancetype)initWithMessageID:(NSString *)messageID
  20. campaignName:(NSString *)campaignName
  21. renderAsTestMessage:(BOOL)renderAsTestMessage
  22. messageType:(FIRInAppMessagingDisplayMessageType)messageType
  23. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  24. appData:(NSDictionary *)appData {
  25. if (self = [super init]) {
  26. #pragma clang diagnostic push
  27. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  28. _campaignInfo = [[FIRInAppMessagingCampaignInfo alloc] initWithMessageID:messageID
  29. campaignName:campaignName
  30. renderAsTestMessage:renderAsTestMessage];
  31. #pragma clang diagnostic pop
  32. _type = messageType;
  33. _triggerType = triggerType;
  34. _appData = [appData copy];
  35. }
  36. return self;
  37. }
  38. - (instancetype)initWithMessageID:(NSString *)messageID
  39. campaignName:(NSString *)campaignName
  40. renderAsTestMessage:(BOOL)renderAsTestMessage
  41. messageType:(FIRInAppMessagingDisplayMessageType)messageType
  42. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType {
  43. if (self = [super init]) {
  44. _campaignInfo = [[FIRInAppMessagingCampaignInfo alloc] initWithMessageID:messageID
  45. campaignName:campaignName
  46. renderAsTestMessage:renderAsTestMessage];
  47. _type = messageType;
  48. _triggerType = triggerType;
  49. _appData = nil;
  50. }
  51. return self;
  52. }
  53. @end
  54. @implementation FIRInAppMessagingCardDisplay
  55. - (void)setBody:(NSString *_Nullable)body {
  56. _body = body;
  57. }
  58. - (void)setLandscapeImageData:(FIRInAppMessagingImageData *_Nullable)landscapeImageData {
  59. _landscapeImageData = landscapeImageData;
  60. }
  61. - (void)setSecondaryActionButton:(FIRInAppMessagingActionButton *_Nullable)secondaryActionButton {
  62. _secondaryActionButton = secondaryActionButton;
  63. }
  64. - (void)setSecondaryActionURL:(NSURL *_Nullable)secondaryActionURL {
  65. _secondaryActionURL = secondaryActionURL;
  66. }
  67. - (instancetype)initWithMessageID:(NSString *)messageID
  68. campaignName:(NSString *)campaignName
  69. renderAsTestMessage:(BOOL)renderAsTestMessage
  70. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  71. titleText:(NSString *)title
  72. textColor:(UIColor *)textColor
  73. portraitImageData:(FIRInAppMessagingImageData *)portraitImageData
  74. backgroundColor:(UIColor *)backgroundColor
  75. primaryActionButton:(FIRInAppMessagingActionButton *)primaryActionButton
  76. primaryActionURL:(NSURL *)primaryActionURL
  77. appData:(NSDictionary *)appData {
  78. #pragma clang diagnostic push
  79. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  80. if (self = [super initWithMessageID:messageID
  81. campaignName:campaignName
  82. renderAsTestMessage:renderAsTestMessage
  83. messageType:FIRInAppMessagingDisplayMessageTypeCard
  84. triggerType:triggerType
  85. appData:appData]) {
  86. #pragma clang diagnostic pop
  87. _title = title;
  88. _textColor = textColor;
  89. _portraitImageData = portraitImageData;
  90. _displayBackgroundColor = backgroundColor;
  91. _primaryActionButton = primaryActionButton;
  92. _primaryActionURL = primaryActionURL;
  93. }
  94. return self;
  95. }
  96. - (instancetype)initWithMessageID:(NSString *)messageID
  97. campaignName:(NSString *)campaignName
  98. renderAsTestMessage:(BOOL)renderAsTestMessage
  99. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  100. titleText:(NSString *)title
  101. textColor:(UIColor *)textColor
  102. portraitImageData:(FIRInAppMessagingImageData *)portraitImageData
  103. backgroundColor:(UIColor *)backgroundColor
  104. primaryActionButton:(FIRInAppMessagingActionButton *)primaryActionButton
  105. primaryActionURL:(NSURL *)primaryActionURL {
  106. #pragma clang diagnostic push
  107. #pragma clang diagnostic ignored "-Wdeprecated-declarations"
  108. if (self = [super initWithMessageID:messageID
  109. campaignName:campaignName
  110. renderAsTestMessage:renderAsTestMessage
  111. messageType:FIRInAppMessagingDisplayMessageTypeCard
  112. triggerType:triggerType
  113. appData:nil]) {
  114. #pragma clang diagnostic pop
  115. _title = title;
  116. _textColor = textColor;
  117. _portraitImageData = portraitImageData;
  118. _displayBackgroundColor = backgroundColor;
  119. _primaryActionButton = primaryActionButton;
  120. _primaryActionURL = primaryActionURL;
  121. }
  122. return self;
  123. }
  124. @end
  125. @implementation FIRInAppMessagingBannerDisplay
  126. - (instancetype)initWithMessageID:(NSString *)messageID
  127. campaignName:(NSString *)campaignName
  128. renderAsTestMessage:(BOOL)renderAsTestMessage
  129. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  130. titleText:(NSString *)title
  131. bodyText:(NSString *)bodyText
  132. textColor:(UIColor *)textColor
  133. backgroundColor:(UIColor *)backgroundColor
  134. imageData:(nullable FIRInAppMessagingImageData *)imageData
  135. actionURL:(nullable NSURL *)actionURL
  136. appData:(NSDictionary *)appData {
  137. if (self = [super initWithMessageID:messageID
  138. campaignName:campaignName
  139. renderAsTestMessage:renderAsTestMessage
  140. messageType:FIRInAppMessagingDisplayMessageTypeBanner
  141. triggerType:triggerType
  142. appData:appData]) {
  143. _title = title;
  144. _bodyText = bodyText;
  145. _textColor = textColor;
  146. _displayBackgroundColor = backgroundColor;
  147. _imageData = imageData;
  148. _actionURL = actionURL;
  149. }
  150. return self;
  151. }
  152. - (instancetype)initWithMessageID:(NSString *)messageID
  153. campaignName:(NSString *)campaignName
  154. renderAsTestMessage:(BOOL)renderAsTestMessage
  155. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  156. titleText:(NSString *)title
  157. bodyText:(NSString *)bodyText
  158. textColor:(UIColor *)textColor
  159. backgroundColor:(UIColor *)backgroundColor
  160. imageData:(nullable FIRInAppMessagingImageData *)imageData
  161. actionURL:(nullable NSURL *)actionURL {
  162. if (self = [super initWithMessageID:messageID
  163. campaignName:campaignName
  164. renderAsTestMessage:renderAsTestMessage
  165. messageType:FIRInAppMessagingDisplayMessageTypeBanner
  166. triggerType:triggerType
  167. appData:nil]) {
  168. _title = title;
  169. _bodyText = bodyText;
  170. _textColor = textColor;
  171. _displayBackgroundColor = backgroundColor;
  172. _imageData = imageData;
  173. _actionURL = actionURL;
  174. }
  175. return self;
  176. }
  177. @end
  178. @implementation FIRInAppMessagingModalDisplay
  179. - (instancetype)initWithMessageID:(NSString *)messageID
  180. campaignName:(NSString *)campaignName
  181. renderAsTestMessage:(BOOL)renderAsTestMessage
  182. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  183. titleText:(NSString *)title
  184. bodyText:(NSString *)bodyText
  185. textColor:(UIColor *)textColor
  186. backgroundColor:(UIColor *)backgroundColor
  187. imageData:(nullable FIRInAppMessagingImageData *)imageData
  188. actionButton:(nullable FIRInAppMessagingActionButton *)actionButton
  189. actionURL:(nullable NSURL *)actionURL
  190. appData:(nullable NSDictionary *)appData {
  191. if (self = [super initWithMessageID:messageID
  192. campaignName:campaignName
  193. renderAsTestMessage:renderAsTestMessage
  194. messageType:FIRInAppMessagingDisplayMessageTypeModal
  195. triggerType:triggerType
  196. appData:appData]) {
  197. _title = title;
  198. _bodyText = bodyText;
  199. _textColor = textColor;
  200. _displayBackgroundColor = backgroundColor;
  201. _imageData = imageData;
  202. _actionButton = actionButton;
  203. _actionURL = actionURL;
  204. }
  205. return self;
  206. }
  207. - (instancetype)initWithMessageID:(NSString *)messageID
  208. campaignName:(NSString *)campaignName
  209. renderAsTestMessage:(BOOL)renderAsTestMessage
  210. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  211. titleText:(NSString *)title
  212. bodyText:(NSString *)bodyText
  213. textColor:(UIColor *)textColor
  214. backgroundColor:(UIColor *)backgroundColor
  215. imageData:(nullable FIRInAppMessagingImageData *)imageData
  216. actionButton:(nullable FIRInAppMessagingActionButton *)actionButton
  217. actionURL:(nullable NSURL *)actionURL {
  218. if (self = [super initWithMessageID:messageID
  219. campaignName:campaignName
  220. renderAsTestMessage:renderAsTestMessage
  221. messageType:FIRInAppMessagingDisplayMessageTypeModal
  222. triggerType:triggerType
  223. appData:nil]) {
  224. _title = title;
  225. _bodyText = bodyText;
  226. _textColor = textColor;
  227. _displayBackgroundColor = backgroundColor;
  228. _imageData = imageData;
  229. _actionButton = actionButton;
  230. _actionURL = actionURL;
  231. }
  232. return self;
  233. }
  234. @end
  235. @implementation FIRInAppMessagingImageOnlyDisplay
  236. - (instancetype)initWithMessageID:(NSString *)messageID
  237. campaignName:(NSString *)campaignName
  238. renderAsTestMessage:(BOOL)renderAsTestMessage
  239. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  240. imageData:(nullable FIRInAppMessagingImageData *)imageData
  241. actionURL:(nullable NSURL *)actionURL
  242. appData:(nullable NSDictionary *)appData {
  243. if (self = [super initWithMessageID:messageID
  244. campaignName:campaignName
  245. renderAsTestMessage:renderAsTestMessage
  246. messageType:FIRInAppMessagingDisplayMessageTypeModal
  247. triggerType:triggerType
  248. appData:appData]) {
  249. _imageData = imageData;
  250. _actionURL = actionURL;
  251. }
  252. return self;
  253. }
  254. - (instancetype)initWithMessageID:(NSString *)messageID
  255. campaignName:(NSString *)campaignName
  256. renderAsTestMessage:(BOOL)renderAsTestMessage
  257. triggerType:(FIRInAppMessagingDisplayTriggerType)triggerType
  258. imageData:(nullable FIRInAppMessagingImageData *)imageData
  259. actionURL:(nullable NSURL *)actionURL {
  260. if (self = [super initWithMessageID:messageID
  261. campaignName:campaignName
  262. renderAsTestMessage:renderAsTestMessage
  263. messageType:FIRInAppMessagingDisplayMessageTypeModal
  264. triggerType:triggerType
  265. appData:nil]) {
  266. _imageData = imageData;
  267. _actionURL = actionURL;
  268. }
  269. return self;
  270. }
  271. @end
  272. @implementation FIRInAppMessagingActionButton
  273. - (instancetype)initWithButtonText:(NSString *)btnText
  274. buttonTextColor:(UIColor *)textColor
  275. backgroundColor:(UIColor *)bkgColor {
  276. if (self = [super init]) {
  277. _buttonText = btnText;
  278. _buttonTextColor = textColor;
  279. _buttonBackgroundColor = bkgColor;
  280. }
  281. return self;
  282. }
  283. @end
  284. @implementation FIRInAppMessagingImageData
  285. - (instancetype)initWithImageURL:(NSString *)imageURL imageData:(NSData *)imageData {
  286. if (self = [super init]) {
  287. _imageURL = imageURL;
  288. _imageRawData = imageData;
  289. }
  290. return self;
  291. }
  292. - (id)copyWithZone:(NSZone *)zone {
  293. FIRInAppMessagingImageData *imageData = [[[self class] allocWithZone:zone] init];
  294. imageData->_imageURL = [_imageURL copyWithZone:zone];
  295. imageData->_imageRawData = [_imageRawData copyWithZone:zone];
  296. return imageData;
  297. }
  298. @end
  299. @implementation FIRInAppMessagingCampaignInfo
  300. - (instancetype)initWithMessageID:(NSString *)messageID
  301. campaignName:(NSString *)campaignName
  302. renderAsTestMessage:(BOOL)renderAsTestMessage {
  303. if (self = [super init]) {
  304. _messageID = messageID;
  305. _campaignName = campaignName;
  306. _renderAsTestMessage = renderAsTestMessage;
  307. }
  308. return self;
  309. }
  310. @end
  311. @implementation FIRInAppMessagingAction
  312. - (instancetype)initWithActionText:(nullable NSString *)actionText
  313. actionURL:(nullable NSURL *)actionURL {
  314. if (self = [super init]) {
  315. _actionText = actionText;
  316. _actionURL = actionURL;
  317. }
  318. return self;
  319. }
  320. @end