Post

Replies

Boosts

Views

Activity

Screenshot within App Clip triggering unexpected NSUserActivityTypeBrowsingWeb
In a SwiftUI app with app clips, taking a screenshot in the app clip triggers a NSUserActivityTypeWeb event. Sometimes the webpageURL is the same as the invocation URL which launched the app clip, other times it is a previous URL which launched another app clip experience. This does not happen when taking a screenshot from the iOS simulator and it does not happen when taking a screenshot within the full app.
0
0
439
Jun ’22
SwiftUI Picker in Form pops back immediately when keyboard is showing
I have a Form in a NavigationView which displays an unknown number of fields for capturing customer input. Some fields are plain TextFields, others are Pickers with multiple selection. If the Picker is far enough down in the Form to be covered by the keyboard when a TextField is focused, then tapping the Picker with the keyboard up prevents the successful transition to the Picker's auto-generated detail view. The detail view is pushed and immediately popped, which prevents selection. I have replicated this issue in a simple single ContentView sample application and have identified a few key findings that lead me to believe this may be a bug: The number of items in the Form prior to the Picker dictates whether this occurs, and differs based on screen size. For iPhone 13, 9+ TextFields before the Picker causes this to happen; for iPhone 13 Pro Max, 12+ TextFields before the Picker causes this to happen. With the same number of total items in the Form, moving the Picker higher on the Form prevents this from happening. If the Picker will not be covered by the keyboard if any TextField is selected, the issue does not happen. If the keyboard is not visible when tapping the Picker, the issue does not happen, regardless of the number of items in the Form.
0
0
497
Apr ’22
URLSessionDownloadTask Disk Caching
I'm looking for some guidance on best practices for caching downloaded images and only downloading them again when they have changed on their remote host. It seems like a common enough scenario that there would be some standard practices, but I have been dissatisfied with the discussions and libraries I have found so far. The basic need is to download images of unknown size, type, and location on-demand cache them to improve load time and prevent unnecessary network traffic know when to re-download the image when the source image has changed Since I do not have control of the images, I prefer to use URLSessionDownloadTask - https://developer.apple.com/documentation/foundation/urlsessiondownloadtask to write the files directly to disk, then use CGImageSourceCreateThumbnailAtIndex - https://developer.apple.com/documentation/imageio/1465099-cgimagesourcecreatethumbnailatin to create appropriately-sized thumbnails rather than download the (potentially large) full-size image into memory. This works great, but to my knowledge, lacks the caching support that URLSessionDataTask offers. What, then, is the proper way for me to update my disk cache of images to ensure that they are up-to-date with their network sources? I have considered making a HEAD request to check the LastModified or ETag headers, but this requires the host to provide this information, which I cannot always rely on. Is this essentially how URLSession and URLCache manages caching under-the-hood? As I was writing this post, I came across the URLSessionDataDelegate method urlSession(_:dataTask:didBecome:) - https://developer.apple.com/documentation/foundation/urlsessiondatadelegate/1409936-urlsession and URLSession.ResponseDisposition. This seems like an intriguing option as well, whereby I begin every task as a URLSessionDataTask, then based on the results of the headers, cancel the task or convert to a download task. Am I just at the liberty of the image hosting service to provide a LastModified date or is there a more sophisticated approach that I'm not considering?
0
0
806
Jan ’21