DocumentActionViewController.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // DocumentActionViewController.swift
  3. // File Provider Extension UI
  4. //
  5. // Created by Marino Faggiana on 30/01/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. import UIKit
  9. import FileProviderUI
  10. class DocumentActionViewController: FPUIActionExtensionViewController {
  11. @IBOutlet weak var cancelButton: UIButton!
  12. @IBOutlet weak var titleError: UILabel!
  13. override func loadView() {
  14. super.loadView()
  15. view.backgroundColor = NCBrandColor.shared.brand
  16. titleError.textColor = NCBrandColor.shared.brandText
  17. cancelButton.setTitleColor(NCBrandColor.shared.brandText, for: .normal)
  18. titleError.text = ""
  19. }
  20. override func prepare(forAction actionIdentifier: String, itemIdentifiers: [NSFileProviderItemIdentifier]) {
  21. }
  22. override func prepare(forError error: Error) {
  23. if let userInfo = (error as NSError).userInfo as NSDictionary?,
  24. let code = userInfo["code"] as? Int {
  25. if code == NCGlobal.shared.errorUnauthorizedFilesPasscode {
  26. titleError?.text = NSLocalizedString("_unauthorizedFilesPasscode_", comment: "")
  27. } else if code == NCGlobal.shared.errorDisableFilesApp {
  28. titleError?.text = NSLocalizedString("_disableFilesApp_", comment: "")
  29. }
  30. } else {
  31. titleError?.text = error.localizedDescription
  32. }
  33. }
  34. @IBAction func doneButtonTapped(_ sender: Any) {
  35. // Perform the action and call the completion block. If an unrecoverable error occurs you must still call the completion block with an error. Use the error code FPUIExtensionErrorCode.failed to signal the failure.
  36. extensionContext.completeRequest()
  37. }
  38. @IBAction func cancelButtonTapped(_ sender: Any) {
  39. extensionContext.cancelRequest(withError: NSError(domain: FPUIErrorDomain, code: Int(FPUIExtensionErrorCode.userCancelled.rawValue), userInfo: nil))
  40. }
  41. }