BannerMessageViewController.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 BannerMessageViewController: 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 showRegularBannerTapped(_ 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 bannerMessage = InAppMessagingBannerDisplay(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. actionURL: URL(string: "http://firebase.com"))
  45. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  46. }
  47. @IBAction func showBannerViewWithoutImageTapped(_ sender: Any) {
  48. verifyLabel.text = "Verification Label"
  49. let modalMessage = InAppMessagingBannerDisplay(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. actionURL: URL(string: "http://firebase.com"))
  59. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  60. }
  61. @IBAction func showBannerViewWithWideImageTapped(_ sender: Any) {
  62. verifyLabel.text = "Verification Label"
  63. let imageRawData = produceImageOfSize(size: CGSize(width: 800, height: 200))
  64. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  65. imageData: imageRawData!)
  66. let modalMessage = InAppMessagingBannerDisplay(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. actionURL: URL(string: "http://firebase.com"))
  76. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  77. }
  78. @IBAction func showBannerViewWithNarrowImageTapped(_ sender: Any) {
  79. verifyLabel.text = "Verification Label"
  80. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 800))
  81. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  82. imageData: imageRawData!)
  83. let modalMessage = InAppMessagingBannerDisplay(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: fiamImageData,
  92. actionURL: URL(string: "http://firebase.com"))
  93. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  94. }
  95. @IBAction func showBannerViewWithLargeBodyTextTapped(_ sender: Any) {
  96. verifyLabel.text = "Verification Label"
  97. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  98. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  99. imageData: imageRawData!)
  100. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  101. campaignName: "testCampaign",
  102. renderAsTestMessage: false,
  103. triggerType: .onAnalyticsEvent,
  104. titleText: normalMessageTitle,
  105. bodyText: longBodyText,
  106. textColor: UIColor.black,
  107. backgroundColor: UIColor.blue,
  108. imageData: fiamImageData,
  109. actionURL: URL(string: "http://firebase.com"))
  110. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  111. }
  112. @IBAction func showBannerViewWithLongTitleTextTapped(_ sender: Any) {
  113. verifyLabel.text = "Verification Label"
  114. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  115. let fiamImageData = InAppMessagingImageData(imageURL: "url not important",
  116. imageData: imageRawData!)
  117. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  118. campaignName: "testCampaign",
  119. renderAsTestMessage: false,
  120. triggerType: .onAnalyticsEvent,
  121. titleText: longTitleText,
  122. bodyText: normalMessageBody,
  123. textColor: UIColor.black,
  124. backgroundColor: UIColor.blue,
  125. imageData: fiamImageData,
  126. actionURL: URL(string: "http://firebase.com"))
  127. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  128. }
  129. }