ModalMessageViewController.swift 13 KB

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