BannerMessageViewController.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. 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 showRegularBannerTapped(_ 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 bannerMessage = InAppMessagingBannerDisplay(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. actionURL: URL(string: "http://firebase.com"))
  43. displayImpl.displayMessage(bannerMessage, displayDelegate: self)
  44. }
  45. @IBAction func showBannerViewWithoutImageTapped(_ sender: Any) {
  46. verifyLabel.text = "Verification Label"
  47. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  48. campaignName: "testCampaign",
  49. renderAsTestMessage: false,
  50. triggerType: .onAnalyticsEvent,
  51. titleText: normalMessageTitle,
  52. bodyText: normalMessageBody,
  53. textColor: UIColor.black,
  54. backgroundColor: UIColor.blue,
  55. imageData: nil,
  56. actionURL: URL(string: "http://firebase.com"))
  57. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  58. }
  59. @IBAction func showBannerViewWithWideImageTapped(_ sender: Any) {
  60. verifyLabel.text = "Verification Label"
  61. let imageRawData = produceImageOfSize(size: CGSize(width: 800, height: 200))
  62. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  63. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  64. campaignName: "testCampaign",
  65. renderAsTestMessage: false,
  66. triggerType: .onAnalyticsEvent,
  67. titleText: normalMessageTitle,
  68. bodyText: normalMessageBody,
  69. textColor: UIColor.black,
  70. backgroundColor: UIColor.blue,
  71. imageData: fiamImageData,
  72. actionURL: URL(string: "http://firebase.com"))
  73. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  74. }
  75. @IBAction func showBannerViewWithNarrowImageTapped(_ sender: Any) {
  76. verifyLabel.text = "Verification Label"
  77. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 800))
  78. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  79. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  80. campaignName: "testCampaign",
  81. renderAsTestMessage: false,
  82. triggerType: .onAnalyticsEvent,
  83. titleText: normalMessageTitle,
  84. bodyText: normalMessageBody,
  85. textColor: UIColor.black,
  86. backgroundColor: UIColor.blue,
  87. imageData: fiamImageData,
  88. actionURL: URL(string: "http://firebase.com"))
  89. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  90. }
  91. @IBAction func showBannerViewWithLargeBodyTextTapped(_ sender: Any) {
  92. verifyLabel.text = "Verification Label"
  93. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  94. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  95. let modalMessage = InAppMessagingBannerDisplay(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: fiamImageData,
  104. actionURL: URL(string: "http://firebase.com"))
  105. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  106. }
  107. @IBAction func showBannerViewWithLongTitleTextTapped(_ sender: Any) {
  108. verifyLabel.text = "Verification Label"
  109. let imageRawData = produceImageOfSize(size: CGSize(width: 200, height: 200))
  110. let fiamImageData = InAppMessagingImageData(imageURL: "url not important", imageData: imageRawData!)
  111. let modalMessage = InAppMessagingBannerDisplay(messageID: "messageId",
  112. campaignName: "testCampaign",
  113. renderAsTestMessage: false,
  114. triggerType: .onAnalyticsEvent,
  115. titleText: longTitleText,
  116. bodyText: normalMessageBody,
  117. textColor: UIColor.black,
  118. backgroundColor: UIColor.blue,
  119. imageData: fiamImageData,
  120. actionURL: URL(string: "http://firebase.com"))
  121. displayImpl.displayMessage(modalMessage, displayDelegate: self)
  122. }
  123. }