Skip to content

Commit bbdab55

Browse files
author
Thomas Taschauer
committed
move documents out of Inbox before opening
1 parent 95930d6 commit bbdab55

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

OpenDocumentReader/AppDelegate.swift

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5858
return false
5959
}
6060

61-
documentBrowserViewController.revealDocument(at: inputURL, importIfNeeded: true) { (revealedDocumentURL, error) in
62-
63-
guard error == nil else {
64-
Crashlytics.crashlytics().record(error: error!)
65-
fatalError("error is not null")
66-
67-
return
68-
}
69-
70-
guard let url = revealedDocumentURL else {
71-
fatalError("revealedDocumentURL is null")
61+
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
62+
let inboxUrl = documentsUrl.appendingPathComponent("Inbox")
63+
64+
let destinationUrl: URL
65+
if (inputURL.absoluteString.contains(inboxUrl.absoluteString)) {
66+
do {
67+
destinationUrl = documentsUrl.appendingPathComponent(inputURL.lastPathComponent)
68+
69+
try FileManager.default.moveItem(at: inputURL, to: destinationUrl)
70+
} catch {
71+
print(error)
72+
fatalError("copying from Inbox failed")
7273

73-
return
74+
return false
7475
}
76+
} else {
77+
destinationUrl = inputURL
78+
}
79+
80+
documentBrowserViewController.revealDocument(at: destinationUrl, importIfNeeded: true) { (revealedDocumentURL, error) in
81+
// ignoring errors because they should pop up in failedToImportDocumentAt too
7582

76-
documentBrowserViewController.presentDocument(at: url)
83+
documentBrowserViewController.presentDocument(at: revealedDocumentURL!)
7784
}
7885

7986
return true

0 commit comments

Comments
 (0)