AutoCopyProcessor.swift 813 B

12345678910111213141516171819202122232425
  1. //
  2. // AutoCopyProcessor.swift
  3. // NotificationServiceExtension
  4. //
  5. // Created by huangfeng on 2024/5/29.
  6. // Copyright © 2024 Fin. All rights reserved.
  7. //
  8. import Foundation
  9. class AutoCopyProcessor: NotificationContentProcessor {
  10. func process(identifier: String, content bestAttemptContent: UNMutableNotificationContent) async throws -> UNMutableNotificationContent {
  11. let userInfo = bestAttemptContent.userInfo
  12. if userInfo["autocopy"] as? String == "1"
  13. || userInfo["automaticallycopy"] as? String == "1"
  14. {
  15. if let copy = userInfo["copy"] as? String {
  16. UIPasteboard.general.string = copy
  17. } else {
  18. UIPasteboard.general.string = bestAttemptContent.body
  19. }
  20. }
  21. return bestAttemptContent
  22. }
  23. }