CommonMessageTestVC.swift 2.6 KB

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