CommonMessageTestVC.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. print("message clicked to follow action url")
  23. messageClosedWithClick = true
  24. }
  25. func impressionDetected(for inAppMessage: InAppMessagingDisplayMessage) {
  26. print("valid impression detected")
  27. }
  28. func displayError(for inAppMessage: InAppMessagingDisplayMessage, error: Error) {
  29. print("error encountered \(error)")
  30. }
  31. func messageDismissed(_ inAppMessage: InAppMessagingDisplayMessage,
  32. dismissType: FIRInAppMessagingDismissType) {
  33. print("message dimissed with type \(dismissType)")
  34. messageClosedDismiss = true
  35. }
  36. // end of InAppMessagingDisplayDelegate functions
  37. let normalMessageTitle = "Firebase In-App Message title"
  38. let normalMessageBody = "Firebase In-App Message body"
  39. let longBodyText = String(repeating: "This is long message body.", count: 40) + "End of body text."
  40. let longTitleText = String(repeating: "This is long message title.", count: 10) + "End of title text."
  41. let startTime = Date().timeIntervalSince1970
  42. let endTime = Date().timeIntervalSince1970 + 1000
  43. let defaultActionButton = InAppMessagingActionButton(buttonText: "Take action",
  44. buttonTextColor: UIColor.black,
  45. backgroundColor: UIColor.yellow)
  46. func produceImageOfSize(size: CGSize) -> Data? {
  47. let color = UIColor.cyan
  48. let rect = CGRect(origin: .zero, size: size)
  49. UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
  50. color.setFill()
  51. UIRectFill(rect)
  52. if let context = UIGraphicsGetCurrentContext() {
  53. context.setStrokeColor(UIColor.red.cgColor)
  54. context.strokeEllipse(in: rect)
  55. }
  56. let imageFromGraphics = UIGraphicsGetImageFromCurrentImageContext()
  57. UIGraphicsEndImageContext()
  58. if let image = imageFromGraphics {
  59. return UIImagePNGRepresentation(image)
  60. } else {
  61. return nil
  62. }
  63. }
  64. }