-
-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MediaUIView - Fix image download bug (#2131) #2215
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import Models | |
import Nuke | ||
import QuickLook | ||
import SwiftUI | ||
import Photos | ||
|
||
public struct MediaUIView: View, @unchecked Sendable { | ||
private let data: [DisplayData] | ||
|
@@ -144,6 +145,8 @@ private struct SavePhotoToolbarItem: ToolbarContent, @unchecked Sendable { | |
state = .unsaved | ||
} | ||
} | ||
} else { | ||
state = .unsaved | ||
} | ||
} | ||
} label: { | ||
|
@@ -180,11 +183,19 @@ private struct SavePhotoToolbarItem: ToolbarContent, @unchecked Sendable { | |
} | ||
return nil | ||
} | ||
|
||
private func saveImage(url: URL) async -> Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to change the var status into a let and use a switch case? Or is the if statement necessary after the requestAuthorization for addOnly? I had something in mind like this: private func saveImage(url: URL) async -> Bool {
guard let image = try? await uiimageFor(url: url) else { return false }
let status: PHAuthorizationStatus
switch PHPhotoLibrary.authorizationStatus(for: .addOnly) {
case .authorized:
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
default:
await PHPhotoLibrary.requestAuthorization(for: .addOnly)
status = PHPhotoLibrary.authorizationStatus(for: .addOnly)
}
return true
} Keeps it more readable without the if statements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, D. Prodano, for your help. The guard statement is definitely a better solution than my if clause. Regarding the other if statements, my intention was to initiate the image download immediately after requesting authorization. Otherwise, the user would have to manually restart the download after granting authorization. What are your thoughts on this approach? |
||
var status = PHPhotoLibrary.authorizationStatus(for: .addOnly) | ||
|
||
if let image = try? await uiimageFor(url: url) { | ||
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) | ||
return true | ||
if status != .authorized { | ||
await PHPhotoLibrary.requestAuthorization(for: .addOnly) | ||
status = PHPhotoLibrary.authorizationStatus(for: .addOnly) | ||
} | ||
if status == .authorized { | ||
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to show empty description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your question, Ankush.
When I leave the description empty, the pop-up displays the standard message: “‘Ice Cubes’ would like to add photos.” To me, this is sufficient, as the user has just pressed the button to download the photo, so everything should be clear.
However, when I add a description, the pop-up feels somewhat redundant:
What would you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay thanks for the explanation, Its better to have some description for the user.