From 2553894db41861706b93786772e7c13777cbe5f4 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 12 Jul 2026 22:13:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E8=B7=B3=E8=BD=AC=E7=B3=BB=E7=BB=9F=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Note/Info.plist | 5 +++++ Note/ViewController.swift | 46 +++++++++------------------------------ 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/Note/Info.plist b/Note/Info.plist index 4f1a75e..d719f0f 100644 --- a/Note/Info.plist +++ b/Note/Info.plist @@ -4,6 +4,11 @@ ITSAppUsesNonExemptEncryption + LSApplicationQueriesSchemes + + mobilenotes + shareddocuments + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes diff --git a/Note/ViewController.swift b/Note/ViewController.swift index 9120603..f48c2d1 100644 --- a/Note/ViewController.swift +++ b/Note/ViewController.swift @@ -6,7 +6,6 @@ // import UIKit -import UniformTypeIdentifiers class ViewController: UIViewController { @@ -97,48 +96,23 @@ extension ViewController: UITableViewDelegate { let viewController = FormatNoteViewController() navigationController?.pushViewController(viewController, animated: true) case "打开文件": - openFiles() + openFilesApp() default: break } } private func openSystemNotesApp() { - guard let url = URL(string: "mobilenotes://") else { return } + openURLIfPossible("mobilenotes://") + } + + private func openFilesApp() { + openURLIfPossible("shareddocuments://") + } + + private func openURLIfPossible(_ string: String) { + guard let url = URL(string: string) else { return } guard UIApplication.shared.canOpenURL(url) else { return } UIApplication.shared.open(url, options: [:], completionHandler: nil) } - - private func openFiles() { - let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.item], asCopy: true) - documentPicker.delegate = self - documentPicker.allowsMultipleSelection = false - present(documentPicker, animated: true) - } -} - -extension ViewController: UIDocumentPickerDelegate { - - func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { - guard let url = urls.first else { return } - let fileName = url.lastPathComponent - - var message: String? - if let data = try? Data(contentsOf: url), - let text = String(data: data, encoding: .utf8), - !text.isEmpty { - message = text - } else { - let attributes = try? FileManager.default.attributesOfItem(atPath: url.path) - let size = attributes?[.size] as? Int64 ?? 0 - message = "无法以文本预览\n大小: \(size) 字节" - } - - let alert = UIAlertController(title: fileName, message: message, preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "确定", style: .default)) - present(alert, animated: true) - } - - func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { - } }