BannerMessageViewController.swift 8.0 KB

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