ModalMessageViewController.swift 14 KB

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