// ログを共有する
func archieveLogsURL(_ onComplete: @escaping (URL?) -> ()) {
var error: NSError?
guard let file = TSHPay.secureLog.files().first?.absoluteURL.deletingLastPathComponent(),
let fileURL = URL(string: "file://\(file.absoluteString)") else {
onComplete(nil)
return
}
NSFileCoordinator().coordinate(
readingItemAt: fileURL,
options: [.forUploading],
error: &error
) { zipUrl in
do {
let tmpUrl = try FileManager.default
.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: zipUrl,
create: true
)
.appendingPathComponent("archive.zip")
try FileManager.default.moveItem(at: zipUrl, to: tmpUrl)
onComplete(tmpUrl)
} catch {
onComplete(nil)
}
}
}