Fixes opening files from outside the app's sandbox.
This commit is contained in:
@@ -53,6 +53,12 @@ struct ContentView: View {
|
|||||||
|
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder()
|
||||||
do {
|
do {
|
||||||
|
let isAccessing = url.startAccessingSecurityScopedResource()
|
||||||
|
defer {
|
||||||
|
if (isAccessing) {
|
||||||
|
url.stopAccessingSecurityScopedResource()
|
||||||
|
}
|
||||||
|
}
|
||||||
let data = try Data(contentsOf: url)
|
let data = try Data(contentsOf: url)
|
||||||
let monsterDTO = try decoder.decode(MonsterDTO.self, from: data)
|
let monsterDTO = try decoder.decode(MonsterDTO.self, from: data)
|
||||||
// TODO: check for some minimal set of properties to ensure this is the expected json schema
|
// TODO: check for some minimal set of properties to ensure this is the expected json schema
|
||||||
@@ -60,7 +66,7 @@ struct ContentView: View {
|
|||||||
// TODO: throw or set an err here and don't set isShowingImportDialog to true if the file didn't match any of our supported monster schemas.
|
// TODO: throw or set an err here and don't set isShowingImportDialog to true if the file didn't match any of our supported monster schemas.
|
||||||
self.isShowingImportDialog = true
|
self.isShowingImportDialog = true
|
||||||
} catch let error as NSError {
|
} catch let error as NSError {
|
||||||
// TODO: handle this better
|
// TODO: show an error message to the user that we were unable to open the file and maybe why.
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user