CommonMessageTestVC.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 Foundation
  17. class CommonMessageTestVC: UIViewController, InAppMessagingDisplayDelegate {
  18. class TestableCampaignInfo: InAppMessagingCampaignInfo {
  19. var writableMessageID: String
  20. var writableCampaignName: String
  21. var writableIsTestMessage: Bool
  22. override var messageID: String {
  23. return writableMessageID
  24. }
  25. override var campaignName: String {
  26. return writableCampaignName
  27. }
  28. override var renderAsTestMessage: Bool {
  29. return writableIsTestMessage
  30. }
  31. init(messageID: String, campaignName: String, isTestMessage: Bool) {
  32. writableMessageID = messageID
  33. writableCampaignName = campaignName
  34. writableIsTestMessage = isTestMessage
  35. }
  36. }
  37. var messageClosedWithClick = false
  38. var messageClosedDismiss = false
  39. // start of InAppMessagingDisplayDelegate functions
  40. func messageClicked(_ inAppMessage: InAppMessagingDisplayMessage,
  41. with action: InAppMessagingAction) {
  42. print("message clicked to follow action url")
  43. messageClosedWithClick = true
  44. }
  45. func impressionDetected(for inAppMessage: InAppMessagingDisplayMessage) {
  46. print("valid impression detected")
  47. }
  48. func displayError(for inAppMessage: InAppMessagingDisplayMessage, error: Error) {
  49. print("error encountered \(error)")
  50. }
  51. func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  52. dismissType: FIRInAppMessagingDismissType) {
  53. print("message dismissed with type \(dismissType)")
  54. messageClosedDismiss = true
  55. }
  56. // end of InAppMessagingDisplayDelegate functions
  57. let normalMessageTitle = "Firebase In-App Message title"
  58. let normalMessageBody = "Firebase In-App Message body"
  59. let longBodyText = String(repeating: "This is long message body.", count: 40) +
  60. "End of body text."
  61. let longTitleText = String(repeating: "This is long message title.", count: 10) +
  62. "End of title text."
  63. let startTime = Date().timeIntervalSince1970
  64. let endTime = Date().timeIntervalSince1970 + 1000
  65. let defaultActionButton = InAppMessagingActionButton(buttonText: "Take action",
  66. buttonTextColor: UIColor.black,
  67. backgroundColor: UIColor.yellow)
  68. let defaultSecondaryActionButton = InAppMessagingActionButton(buttonText: "Take another action",
  69. buttonTextColor: UIColor.black,
  70. backgroundColor: UIColor.yellow)
  71. let longTextButton =
  72. InAppMessagingActionButton(buttonText: "Hakuna matata, it's a wonderful phrase",
  73. buttonTextColor: UIColor.black,
  74. backgroundColor: UIColor.white)
  75. func produceImageOfSize(size: CGSize) -> Data? {
  76. let color = UIColor.cyan
  77. let rect = CGRect(origin: .zero, size: size)
  78. UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
  79. color.setFill()
  80. UIRectFill(rect)
  81. if let context = UIGraphicsGetCurrentContext() {
  82. context.setStrokeColor(UIColor.red.cgColor)
  83. context.strokeEllipse(in: rect)
  84. }
  85. let imageFromGraphics = UIGraphicsGetImageFromCurrentImageContext()
  86. UIGraphicsEndImageContext()
  87. if let image = imageFromGraphics {
  88. return image.pngData()
  89. } else {
  90. return nil
  91. }
  92. }
  93. }