Settings: Export log: Perform file operations in a background thread

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-12-08 01:21:46 +05:30
parent 06a783f50a
commit 71568d1899
1 changed files with 32 additions and 27 deletions

View File

@ -96,6 +96,8 @@ class SettingsTableViewController: UITableViewController {
let timeStampString = dateFormatter.string(from: Date())
let destinationURL = destinationDir.appendingPathComponent("wireguard-log-\(timeStampString).txt")
DispatchQueue.global(qos: .userInitiated).async {
if (FileManager.default.fileExists(atPath: destinationURL.path)) {
let isDeleted = FileManager.deleteFile(at: destinationURL)
if (!isDeleted) {
@ -118,6 +120,7 @@ class SettingsTableViewController: UITableViewController {
return
}
DispatchQueue.main.async {
let activityVC = UIActivityViewController(activityItems: [destinationURL], applicationActivities: nil)
// popoverPresentationController shall be non-nil on the iPad
activityVC.popoverPresentationController?.sourceView = sourceView
@ -129,6 +132,8 @@ class SettingsTableViewController: UITableViewController {
self.present(activityVC, animated: true)
}
}
}
}
// MARK: UITableViewDataSource