Fix not being able to import keys on iOS 16

This commit is contained in:
Shadowfacts 2022-09-16 21:36:30 -04:00
parent 02e229042a
commit 07f9619217
1 changed files with 15 additions and 3 deletions

View File

@ -46,14 +46,22 @@ struct PreferencesView: View {
}
.fileExporter(isPresented: $isPresentingExport, document: BackupDocument(data: store.data), contentType: .propertyList, defaultFilename: "OTPBackup") { (_) in
}
.fileImporter(isPresented: $isPresentingImport, allowedContentTypes: [.propertyList], allowsMultipleSelection: false) { (result) in
.fileImporter(isPresented: $isPresentingImport, allowedContentTypes: [.propertyList]) { (result) in
switch result {
case let .failure(error):
self.importFailedError = error
self.isPresentingImportFailedAlert = true
case let .success(urls):
case let .success(url):
guard url.startAccessingSecurityScopedResource() else {
self.importFailedError = ImportError.accessingSecurityScopedResource
self.isPresentingImportFailedAlert = true
return
}
defer {
url.stopAccessingSecurityScopedResource()
}
do {
let backup = try BackupDocument(url: urls.first!)
let backup = try BackupDocument(url: url)
store.updateFromStore(backup.data, replaceExisting: clearBeforeImport)
dismiss()
} catch {
@ -71,6 +79,10 @@ struct PreferencesView: View {
}
}
enum ImportError: LocalizedError {
case accessingSecurityScopedResource
}
}
struct PreferencesView_Previews: PreviewProvider {