CommonMessageTestVC.swift 3.3 KB

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