Following WWDC24 video "Discover Swift enhancements in the Vision framework" recommendations (cfr video at 10'41"), I used the following code to perform multiple new iOS 18 `RecognizedTextRequest' in parallel.
Problem: if more than 2 request are run in parallel, the request will hang, leaving the app in a state where no more requests can be started. -> deadlock
I tried other ways to run the requests, but no matter the method employed, or what device I use: no more than 2 requests can ever be run in parallel.
func triggerDeadlock() {}
try await withThrowingTaskGroup(of: Void.self) { group in
// See: WWDC 2024 Discover Siwft enhancements in the Vision framework at 10:41
// ############## THIS IS KEY
let maxOCRTasks = 5 // On a real-device, if more than 2 RecognizeTextRequest are launched in parallel using tasks, the request hangs
// ############## THIS IS KEY
for idx in 0..<maxOCRTasks {
let url = ... // URL to some image
group.addTask {
// Perform OCR
let _ = await performOCRRequest(on: url: url)
}
}
var nextIndex = maxOCRTasks
for try await _ in group { // Wait for the result of the next child task that finished
if nextIndex < pageCount {
group.addTask {
let url = ... // URL to some image
// Perform OCR
let _ = await performOCRRequest(on: url: url)
}
nextIndex += 1
}
}
}
}
// MARK: - ASYNC/AWAIT version with iOS 18
@available(iOS 18, *)
func performOCRRequest(on url: URL) async throws -> [RecognizedText] {
// Create request
var request = RecognizeTextRequest() // Single request: no need for ImageRequestHandler
// Configure request
request.recognitionLevel = .accurate
request.automaticallyDetectsLanguage = true
request.usesLanguageCorrection = true
request.minimumTextHeightFraction = 0.016
// Perform request
let textObservations: [RecognizedTextObservation] = try await request.perform(on: url)
// Convert [RecognizedTextObservation] to [RecognizedText]
return textObservations.compactMap { observation in
observation.topCandidates(1).first
}
}
I also found this Swift forums post mentioning something very similar.
I also opened a feedback: FB17240843
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
One can configure the languages of a (VN)RecognizeTextRequest with either:
.automatic: language to be detected
a specific language, say Spanish
If the request is configured with .automatic and successfully detects Spanish, will the results be exactly equivalent compared to a request made with Spanish set as language?
I could not find any information about this, and this is very important for the core architecture of my app.
Thanks!
On iOS 18, I'm trying to index documents in Spotlight using the new combination of AppIntents+IndexedEntity.
However, I don't seem to be able to index the textContent of the document. Only the displayName seems to be indexed.
As recommended, I start with the defaultAttributeSet:
/// I call this function to index in Spotlight
static func indexInSpotlight(document: Document) async {
do {
if let entity = document.toEntity {
try await CSSearchableIndex.default().indexAppEntities([entity])
}
} catch {
DLog("Spotlight: could not index document: \(document.name ?? "")")
}
}
/// This is the corresponding IndexedEntity with the attributeSet
@available(iOS 18, *)
extension DocumentEntity {
var attributeSet: CSSearchableItemAttributeSet {
let attributeSet = defaultAttributeSet
attributeSet.title = title
attributeSet.displayName = title
attributeSet.textContent = docContent
attributeSet.thumbnailData = thumbnailData
attributeSet.kind = "document"
attributeSet.creator = Constants.APP_NAME
return attributeSet
}
}
How can I have more that the displayName to be indexed? Thanks :-)
Note: I have had issues with CMAltimeter since whats seems to have been a major undocumented modification since iOS 17.4.
So I'm using the CMAltimeter absolute locations delivery.
Sometimes, the altimeter seems to be in an uncalibrated mode and therefore, no altitude delivery happens.
Is there a way to be inform of such state? Currently, it just doesn't work and I can't inform the user about this. They just think the app is broken
What message should I give to the users to accelerate the calibration such that the CMAltimeter will work again?
Also, users have reported that the CMAltimeter can temporarily stop delivering altitude updates, even though it should.
So I guess my question resumes to this:
Whats the best practice to handle an uncalibrated CMAltimeter?
Thanks!
My app reports a lot of crashes from 18.2 users.
I have been able to narrow down the issue to this line of code:
CGImageDestinationFinalize(imageDestination)
The error is Thread 93: EXC_BAD_ACCESS (code=1, address=0x146318000)
But I have no idea why this suddently started to crash.
Here is the code of the function:
private func estimateSizeUsingThumbnailMethod(fromImageURL url: URL, imageSettings: ImageSettings) -> (Int, Int) {
let sourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary
guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions),
let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any],
let imageWidth = imageProperties[kCGImagePropertyPixelWidth] as? CGFloat,
let imageHeight = imageProperties[kCGImagePropertyPixelHeight] as? CGFloat else {
return (0, 0)
}
let maxImageSize = max(imageWidth, imageHeight)
let thumbMaxSize = min(2400, maxImageSize) // Use original size if possible, but not if larger than 2400, in this case we'll extrapolate from thumbnail
let downsampleOptions = [
kCGImageSourceCreateThumbnailFromImageAlways: true,
kCGImageSourceCreateThumbnailWithTransform: true,
kCGImageSourceThumbnailMaxPixelSize: thumbMaxSize as CFNumber,
] as CFDictionary
guard let cgImage = CGImageSourceCreateThumbnailAtIndex(source, 0, downsampleOptions) else {
DLog("CGImage thumb creation error")
return (0, 0)
}
let data = NSMutableData()
guard let imageDestination = CGImageDestinationCreateWithData(data, UTType.jpeg.identifier as CFString, 1, nil) else {
DLog("CGImage destination creation error")
return (0, 0)
}
let destinationProperties = [
kCGImageDestinationLossyCompressionQuality: imageSettings.quality.compressionRatio() // Set jpeg compression ratio
] as CFDictionary
CGImageDestinationAddImage(imageDestination, cgImage, destinationProperties)
CGImageDestinationFinalize(imageDestination) // <----- CRASHES HERE with EXC_BAD_ACCESS
...
}
So far, I'm stuck. Any idea that could help would be greatly appreciated, as I'm scared that this crash will propagate on the official release of 18.2
Before iPadOS 18, I was using hidesBottomBarWhenPushed, and it worked beautifully.
Now, it's broken/not working.
How are we supposed to hide the new tab bar nowadays?
Reproducible on iOS 17.4.1 (maybe before) & iOS 17.5. Maybe iOS 17.4 but I can't test it.
NSMotionUsageDescription is correctly set (and has always been)
Fitness activity & motion authorization are correctly enabled
The delivery for absolute altitude changes became super slow, and might be inaccurate. The only value I get is exactly the same as the GPS altitude. The accelerometer data does not seem to be taken into account anymore.
This critical bug has broken two apps of mine.
How could I quickly solve this?
Thank you!
PS: code is dead simple
let operationQueue = OperationQueue()
self.altimeter.startAbsoluteAltitudeUpdates(to: operationQueue) { [weak self] (data, error) in
guard let self = self else { return }
guard let data else { return }
DispatchQueue.main.async { // Use this value for display
self.altitude = Measurement(value: data.altitude, unit: UnitLength.meters)
/* DEBUG VIEW */
self.updateDebugView(with: data.altitude)
}
}
I'm using Watch Connectivity to transfer files from the Watch to its paired iOS device.
File transfer is successful in my first tests, but obviously I need to erase the source file when it is - successfully - sent.
When should I do that?
just after initiating the file transfer, using transferFile(file: NSURL, metadata: [String : AnyObject]) when getting the returned WCSessionFileTransfer?
when getting the callback func session(_ session: WCSession, didFinish fileTransfer: WCSessionFileTransfer ? --> but will the callback always be called, even if the transfer finishes while the app is in background?
some other time?
NB: I'd really want to avoid implementing a custom 'ack' system, thus not using any user info/application context transfer.
Hi,
title says it all: I have Transaction.currentEntitlements returning expired subscriptions (testing both transaction expirationDate & RenewalState).
Environment: local via .storekit file. Subscription duration is shortened for testing. Could it be the issue? The sub duration is normally 1 year.
The documentation says it should only returns active subscription (RenewalState.subscribed) or in grace period (RenewalState.inGracePeriod).
Since iOS 16.4, my apps hangs when I dismiss the keyboard in viewWillDisappear().
Here is my code:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
DLog("will disappear <<<<<")
dismissKeyboard()
}
fileprivate func dismissKeyboard() {
self.filenameSearchTextField.resignFirstResponder()
}
App hangs, CPU is 100%, memory usage is increasing.
The hangs happen on the resignFirstResponder() call.
What's going on here?