Saving file to disk in catalyst version

This commit is contained in:
Selim Mustafaev 2022-12-25 23:34:09 +03:00
parent 07f3d285d4
commit 512a50b217
3 changed files with 24 additions and 4 deletions

View File

@ -1080,7 +1080,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 97;
CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
@ -1105,7 +1105,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 97;
CURRENT_PROJECT_VERSION = 100;
DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;

View File

@ -10,6 +10,8 @@
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.location</key>

View File

@ -209,8 +209,11 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
do {
let tmpUrl = FileManager.default.tmpUrl(name: "search", ext: "csv")
try csvString.write(to: tmpUrl, atomically: true, encoding: .utf8)
let activityController = UIActivityViewController(activityItems: [tmpUrl], applicationActivities: nil)
self.present(activityController, animated: true)
#if targetEnvironment(macCatalyst)
self.save(file: tmpUrl)
#else
self.share(file: tmpUrl)
#endif
} catch {
HUD.show(error: error)
}
@ -221,6 +224,21 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe
.disposed(by: bag)
}
func share(file url: URL) {
let activityController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
self.present(activityController, animated: true)
}
func save(file url: URL) {
if #available(iOS 14, *) {
let controller = UIDocumentPickerViewController(forExporting: [url])
self.present(controller, animated: true)
} else {
let controller = UIDocumentPickerViewController(url: url, in: .exportToService)
present(controller, animated: true)
}
}
// MARK: - UITableViewDelegate
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {