Skip to content

Commit 43597b4

Browse files
committed
fix: crash when granting app permission to access photos library (dispatch assert in callback)
Signed-off-by: Tommy van der Vorst <tommy@pixelspark.nl>
1 parent 4b0aa63 commit 43597b4

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Sushitrain/PhotoBackupView.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ struct PhotoBackupSettingsView: View {
131131
else {
132132
Text("Synctrain cannot access your photo library right now")
133133
Button("Allow Synctrain to access photos") {
134-
PHPhotoLibrary.requestAuthorization { status in
135-
DispatchQueue.main.async {
136-
authorizationStatus = status
137-
}
138-
}
134+
self.requestAuthorization()
139135
}
140136
}
141137

@@ -337,6 +333,14 @@ struct PhotoBackupSettingsView: View {
337333
}
338334
}
339335

336+
private func requestAuthorization() {
337+
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
338+
Task { @MainActor in
339+
authorizationStatus = status
340+
}
341+
}
342+
}
343+
340344
private func update() async {
341345
authorizationStatus = PHPhotoLibrary.authorizationStatus()
342346
self.folders = await appState.folders().filter({ $0.isSuitablePhotoBackupDestination }).sorted()

Sushitrain/PhotoFolderSettingsView.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,7 @@ private struct PhotoFolderAlbumSettingsView: View {
211211
else {
212212
Text("Synctrain cannot access your photo library right now")
213213
Button("Allow Synctrain to access photos") {
214-
PHPhotoLibrary.requestAuthorization { status in
215-
DispatchQueue.main.async {
216-
authorizationStatus = status
217-
}
218-
}
214+
self.requestAuthorization()
219215
}
220216
}
221217
}
@@ -279,6 +275,14 @@ private struct PhotoFolderAlbumSettingsView: View {
279275
.navigationTitle(dirName.isEmpty ? "Add album" : "Settings for '\(dirName)'")
280276
}
281277

278+
private func requestAuthorization() {
279+
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
280+
Task { @MainActor in
281+
authorizationStatus = status
282+
}
283+
}
284+
}
285+
282286
func loadAlbums() -> [PHAssetCollection] {
283287
var albums: [PHAssetCollection] = []
284288
let options = PHFetchOptions()

0 commit comments

Comments
 (0)