ModalMessageViewController.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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
  17. class ModalMessageViewController: CommonMessageTestVC {
  18. let displayImpl = InAppMessagingDefaultDisplayImpl()
  19. @IBOutlet var verifyLabel: UILabel!
  20. override func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  21. with action: InAppMessagingAction) {
  22. super.messageClicked(inAppMessage, with: action)
  23. verifyLabel.text = "message clicked!"
  24. }
  25. override func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  26. dismissType: FIRInAppMessagingDismissType) {
  27. super.messageDismissed(inAppMessage, dismissType: dismissType)
  28. verifyLabel.text = "message dismissed!"
  29. }
  30. @IBAction func showRegular(_ sender: Any) {
  31. verifyLabel.text = "Verification Label"
  32. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  33. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  34. imageData: imageRawData!)
  35. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  36. campaignName: "testCampaign",
  37. renderAsTestMessage: false,
  38. triggerType: .onAnalyticsEvent,
  39. titleText: normalMessageTitle,
  40. bodyText: normalMessageBody,
  41. textColor: UIColor.black,
  42. backgroundColor: UIColor.blue,
  43. imageData: fiamImageData,
  44. actionButton: defaultActionButton,
  45. actionURL: URL(string: "http://firebase.com"))
  46. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  47. }
  48. @IBAction func showWithoutImage(_ sender: Any) {
  49. verifyLabel.text = "Verification Label"
  50. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  51. campaignName: "testCampaign",
  52. renderAsTestMessage: false,
  53. triggerType: .onAnalyticsEvent,
  54. titleText: normalMessageTitle,
  55. bodyText: normalMessageBody,
  56. textColor: UIColor.black,
  57. backgroundColor: UIColor.blue,
  58. imageData: nil,
  59. actionButton: defaultActionButton,
  60. actionURL: URL(string: "http://firebase.com"))
  61. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  62. }
  63. @IBAction func showWithoutButton(_ sender: Any) {
  64. verifyLabel.text = "Verification Label"
  65. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  66. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  67. imageData: imageRawData!)
  68. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  69. campaignName: "testCampaign",
  70. renderAsTestMessage: false,
  71. triggerType: .onAnalyticsEvent,
  72. titleText: normalMessageTitle,
  73. bodyText: normalMessageBody,
  74. textColor: UIColor.black,
  75. backgroundColor: UIColor.blue,
  76. imageData: fiamImageData,
  77. actionButton: nil,
  78. actionURL: nil)
  79. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  80. }
  81. @IBAction func showWithoutImageAndButton(_ sender: Any) {
  82. verifyLabel.text = "Verification Label"
  83. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  84. campaignName: "testCampaign",
  85. renderAsTestMessage: false,
  86. triggerType: .onAnalyticsEvent,
  87. titleText: normalMessageTitle,
  88. bodyText: normalMessageBody,
  89. textColor: UIColor.black,
  90. backgroundColor: UIColor.blue,
  91. imageData: nil,
  92. actionButton: nil,
  93. actionURL: nil)
  94. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  95. }
  96. @IBAction func showWithLargeBody(_ sender: Any) {
  97. verifyLabel.text = "Verification Label"
  98. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  99. campaignName: "testCampaign",
  100. renderAsTestMessage: false,
  101. triggerType: .onAnalyticsEvent,
  102. titleText: normalMessageTitle,
  103. bodyText: longBodyText,
  104. textColor: UIColor.black,
  105. backgroundColor: UIColor.blue,
  106. imageData: nil,
  107. actionButton: defaultActionButton,
  108. actionURL: URL(string: "http://firebase.com"))
  109. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  110. }
  111. @IBAction func showWithLargeTitleAndBody(_ sender: Any) {
  112. verifyLabel.text = "Verification Label"
  113. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  114. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  115. imageData: imageRawData!)
  116. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  117. campaignName: "testCampaign",
  118. renderAsTestMessage: false,
  119. triggerType: .onAnalyticsEvent,
  120. titleText: longTitleText,
  121. bodyText: longBodyText,
  122. textColor: UIColor.black,
  123. backgroundColor: UIColor.blue,
  124. imageData: fiamImageData,
  125. actionButton: defaultActionButton,
  126. actionURL: URL(string: "http://firebase.com"))
  127. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  128. }
  129. @IBAction func showWithLargeTitle(_ sender: Any) {
  130. verifyLabel.text = "Verification Label"
  131. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  132. campaignName: "testCampaign",
  133. renderAsTestMessage: false,
  134. triggerType: .onAnalyticsEvent,
  135. titleText: longBodyText,
  136. bodyText: normalMessageBody,
  137. textColor: UIColor.black,
  138. backgroundColor: UIColor.blue,
  139. imageData: nil,
  140. actionButton: defaultActionButton,
  141. actionURL: URL(string: "http://firebase.com"))
  142. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  143. }
  144. @IBAction func showWithLargeTitleAndBodyWithoutImage(_ sender: Any) {
  145. verifyLabel.text = "Verification Label"
  146. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  147. campaignName: "testCampaign",
  148. renderAsTestMessage: false,
  149. triggerType: .onAnalyticsEvent,
  150. titleText: longTitleText,
  151. bodyText: longBodyText,
  152. textColor: UIColor.black,
  153. backgroundColor: UIColor.blue,
  154. imageData: nil,
  155. actionButton: defaultActionButton,
  156. actionURL: URL(string: "http://firebase.com"))
  157. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  158. }
  159. @IBAction func showWithLargeTitleWithoutBodyWithoutImageWithoutButton(_ sender: Any) {
  160. verifyLabel.text = "Verification Label"
  161. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  162. campaignName: "testCampaign",
  163. renderAsTestMessage: false,
  164. triggerType: .onAnalyticsEvent,
  165. titleText: longBodyText,
  166. bodyText: "",
  167. textColor: UIColor.black,
  168. backgroundColor: UIColor.blue,
  169. imageData: nil,
  170. actionButton: nil,
  171. actionURL: nil)
  172. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  173. }
  174. @IBAction func showWithWideImage(_ sender: Any) {
  175. verifyLabel.text = "Verification Label"
  176. let imageRawData = produceImageOfSize(size: CGSize(width: 600, height: 200))
  177. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  178. imageData: imageRawData!)
  179. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  180. campaignName: "testCampaign",
  181. renderAsTestMessage: false,
  182. triggerType: .onAnalyticsEvent,
  183. titleText: normalMessageTitle,
  184. bodyText: normalMessageBody,
  185. textColor: UIColor.black,
  186. backgroundColor: UIColor.blue,
  187. imageData: fiamImageData,
  188. actionButton: defaultActionButton,
  189. actionURL: URL(string: "http://firebase.com"))
  190. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  191. }
  192. @IBAction func showWithThinImage(_ sender: Any) {
  193. verifyLabel.text = "Verification Label"
  194. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 600))
  195. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  196. imageData: imageRawData!)
  197. let modalMessage = InAppMessagingModalDisplay(messageID: "messageId",
  198. campaignName: "testCampaign",
  199. renderAsTestMessage: false,
  200. triggerType: .onAnalyticsEvent,
  201. titleText: normalMessageTitle,
  202. bodyText: normalMessageBody,
  203. textColor: UIColor.black,
  204. backgroundColor: UIColor.blue,
  205. imageData: fiamImageData,
  206. actionButton: defaultActionButton,
  207. actionURL: URL(string: "http://firebase.com"))
  208. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  209. }
  210. override func viewDidLoad() {
  211. super.viewDidLoad()
  212. // Do any additional setup after loading the view.
  213. }
  214. override func didReceiveMemoryWarning() {
  215. super.didReceiveMemoryWarning()
  216. // Dispose of any resources that can be recreated.
  217. }
  218. }