Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 657442249a | |||
| 24b69cf72f | |||
| a76be6e871 |
@@ -148,6 +148,7 @@
|
||||
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = Note/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = "备忘录格式化助手";
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
|
||||
@@ -180,6 +181,7 @@
|
||||
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = Note/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = "备忘录格式化助手";
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
@@ -21,7 +22,8 @@ class ViewController: UIViewController {
|
||||
[
|
||||
MenuItem(icon: "note.text", iconColor: .systemYellow, title: "打开备忘录"),
|
||||
MenuItem(icon: "doc.text", iconColor: .systemBlue, title: "格式化日志"),
|
||||
MenuItem(icon: "text.alignleft", iconColor: .systemGreen, title: "格式化笔记")
|
||||
MenuItem(icon: "text.alignleft", iconColor: .systemGreen, title: "格式化笔记"),
|
||||
MenuItem(icon: "folder", iconColor: .systemOrange, title: "打开文件")
|
||||
]
|
||||
]
|
||||
|
||||
@@ -94,6 +96,8 @@ extension ViewController: UITableViewDelegate {
|
||||
case "格式化笔记":
|
||||
let viewController = FormatNoteViewController()
|
||||
navigationController?.pushViewController(viewController, animated: true)
|
||||
case "打开文件":
|
||||
openFiles()
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -104,4 +108,37 @@ extension ViewController: UITableViewDelegate {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user