NSUserActivity.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // NSUserActivity.swift
  3. // Runner
  4. //
  5. // Created by Hien Nguyen on 20/02/2022.
  6. //
  7. import Foundation
  8. import Intents
  9. extension NSUserActivity: StartCallConvertible {
  10. public var handle: String? {
  11. guard
  12. let interaction = interaction,
  13. let startCallIntent = interaction.intent as? SupportedStartCallIntent,
  14. let contact = startCallIntent.contacts?.first
  15. else {
  16. return nil
  17. }
  18. print(interaction.intent)
  19. return contact.personHandle?.value
  20. }
  21. public var isVideo: Bool? {
  22. guard
  23. let interaction = interaction,
  24. let startCallIntent = interaction.intent as? SupportedStartCallIntent
  25. else {
  26. return nil
  27. }
  28. return startCallIntent is INStartVideoCallIntent
  29. }
  30. }
  31. protocol StartCallConvertible {
  32. var handle: String? { get }
  33. var isVideo: Bool? { get }
  34. }
  35. extension StartCallConvertible {
  36. var isVideo: Bool? {
  37. return nil
  38. }
  39. }
  40. protocol SupportedStartCallIntent {
  41. var contacts: [INPerson]? { get }
  42. }
  43. extension INStartAudioCallIntent: SupportedStartCallIntent {}
  44. extension INStartVideoCallIntent: SupportedStartCallIntent {}