CommonMessageTestVC.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. 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: FIRInAppMessagingDismissType) {
  34. print("message dimissed 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) + "End of body text."
  41. let longTitleText = String(repeating: "This is long message title.", count: 10) + "End of title text."
  42. let startTime = Date().timeIntervalSince1970
  43. let endTime = Date().timeIntervalSince1970 + 1000
  44. let defaultActionButton = InAppMessagingActionButton(buttonText: "Take action",
  45. buttonTextColor: UIColor.black,
  46. backgroundColor: UIColor.yellow)
  47. let defaultSecondaryActionButton = InAppMessagingActionButton(buttonText: "Take another action",
  48. buttonTextColor: UIColor.black,
  49. backgroundColor: UIColor.yellow)
  50. let longTextButton = InAppMessagingActionButton(buttonText: "Hakuna matata, it's a wonderful phrase",
  51. buttonTextColor: UIColor.black,
  52. backgroundColor: UIColor.white)
  53. func produceImageOfSize(size: CGSize) -> Data? {
  54. let color = UIColor.cyan
  55. let rect = CGRect(origin: .zero, size: size)
  56. UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
  57. color.setFill()
  58. UIRectFill(rect)
  59. if let context = UIGraphicsGetCurrentContext() {
  60. context.setStrokeColor(UIColor.red.cgColor)
  61. context.strokeEllipse(in: rect)
  62. }
  63. let imageFromGraphics = UIGraphicsGetImageFromCurrentImageContext()
  64. UIGraphicsEndImageContext()
  65. if let image = imageFromGraphics {
  66. return UIImagePNGRepresentation(image)
  67. } else {
  68. return nil
  69. }
  70. }
  71. }