Fix not being able to import keys on iOS 16
This commit is contained in:
parent
02e229042a
commit
07f9619217
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue