Post

Replies

Boosts

Views

Activity

Handwritten text recognition working poorly on iOS 16 beta ?
That's a follow up of a previous thread. https://developer.apple.com/forums/thread/707130 I did some test on iOS 16 simulator with Xcode 14ß. Recognition is very poor. And recognition rate of some single letters (an L or an I for instance) is zero (literally). Same code worked better (success 50% for same single letters) with iOS 15.2. Did something change on iOS 16 ? I filed a bug report: Jun 7, 2022 at 3:28 PM – FB10066541
3
0
2.1k
Jun ’22
Add Return key subview to keyboard
That's an old question (this thread https://developer.apple.com/forums/thread/16375 dates back iOS9 or this other thread https://stackoverflow.com/questions/67249956/uisearchbar-warning-uitexteffectswindow-should-not-become-key-please-file-a-bu), but I've not found a comprehensive answer yet. I need to add a Return key to a numeric keyboard (BTW, how is it it does not exist in standard ?) I used to do it using let keyBoardWindow = UIApplication.shared.windows.last  to get the keyboard window and then adding the subview (self.returnButton) to it keyBoardWindow?.addSubview(self.returnButton) Worked great and still works OK with iOS 15. But we are told to use connectedScenes instead… So I adapt code: var keyBoardWindow: UIWindow? = nil if #available(iOS 13.0, *) { // use connectedScenes let scenes = UIApplication.shared.connectedScenes let windowScene = scenes.first as? UIWindowScene if let kbWindow = windowScene?.windows.last { keyBoardWindow = kbWindow } } else { keyBoardWindow = UIApplication.shared.windows.last } It runs, but subview does not show. The problem is that keyboardWindow used to be a UIRemoteKeyboardWindow (the true keyboard window) and now is UITextEffectsWindow, which is not the real keyboardWindow. So adding subview to it adds improperly in the hierarchy. Note: someone detailed the view hierarchy here: https://developer.apple.com/forums/thread/664547 UIWindow UITextEffectsWindow     UIInputWindowController         UIInputSetContainerView               UIInputSetHostView               UIEditingOverlayViewController                      UIEditingOverlayGestureView I guess I have to add subview to something else than UITextEffectsWindow (keyBoardWindow), but to what ? I tried      keyBoardWindow = kbWindow.superview as? UIWindow to no avail. I also tried to debug view hierarchy, but keyboard does not show in debugView.
9
0
2.4k
Jun ’22
VNRecognizeTextRequest from a text drawn in UIImageView returns empty results
Here is the setup. I have an UIImageView in which I write some text, using UIGraphicsBeginImageContext. I pass this image to the OCR func: func ocrText(onImage: UIImage?) { let request = VNRecognizeTextRequest { request, error in guard let observations = request.results as? [VNRecognizedTextObservation] else { fatalError("Received invalid observations") } print("observations", observations.count) for observation in observations { if observation.topCandidates(1).isEmpty { continue } } } // end of request handler request.recognitionLanguages = ["fr"] let requests = [request] DispatchQueue.global(qos: .userInitiated).async { let ocrGroup = DispatchGroup() guard let img = onImage?.cgImage else { return } // Conversion to cgImage works OK                 print("img", img, img.width)                 let (_, _) = onImage!.logImageSizeInKB(scale: 1) ocrGroup.enter() let handler = VNImageRequestHandler(cgImage: img, options: [:]) try? handler.perform(requests) ocrGroup.leave() ocrGroup.wait() } } Problem is that observations is an empty array. I get the following logs: img <CGImage 0x7fa53b350b60> (DP) <<CGColorSpace 0x6000032f1e00> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)> width = 398, height = 164, bpc = 8, bpp = 32, row bytes = 1600 kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 398 ImageSize(KB): 5 ko 2022-06-02 17:21:03.734258+0200 App[6949:2718734] Metal API Validation Enabled observations 0 Which shows image is loaded and converted correctly to cgImage. But no observations. Now, if I use the same func on a snapshot image of the text drawn on screen, it works correctly. Is there a difference between the image created by camera and image drawn in CGContext ? Here is how mainImageView!.image (used in ocr) is created in a subclass of UIImageView: override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { // Merge tempImageView into mainImageView UIGraphicsBeginImageContext(mainImageView!.frame.size) mainImageView!.image?.draw(in: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height), blendMode: .normal, alpha: 1.0) tempImageView!.image?.draw(in: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height), blendMode: .normal, alpha: opacity) mainImageView!.image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() tempImageView?.image = nil } I also draw the created image in a test UIImageView and get the correct image. Here are the logs for the drawn texte and from the capture: Drawing doesn't work img <CGImage 0x7fb96b81a030> (DP) <<CGColorSpace 0x600003322160> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)> width = 398, height = 164, bpc = 8, bpp = 32, row bytes = 1600 kCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 398 ImageSize(KB): 5 ko 2022-06-02 15:38:51.115476+0200 Numerare[5313:2653328] Metal API Validation Enabled observations 0 Screen shot : Works img <CGImage 0x7f97641720f0> (IP) <<CGColorSpace 0x60000394c960> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; iMac)> width = 570, height = 276, bpc = 8, bpp = 32, row bytes = 2280 kCGImageAlphaNoneSkipLast | 0 (default byte order) | kCGImagePixelFormatPacked is mask? No, has masking color? No, has soft mask? No, has matte? No, should interpolate? Yes 570 ImageSize(KB): 5 ko 2022-06-02 15:43:32.158701+0200 Numerare[5402:2657059] Metal API Validation Enabled 2022-06-02 15:43:33.122941+0200 Numerare[5402:2657057] [WARNING] Resource not found for 'fr_FR'. Character language model will be disabled during language correction. observations 1 Is there an issue with kCGColorSpaceModelRGB ?
9
0
3k
Jun ’22
Contribution to Quinn’s Top Ten DevForums Tips
Hi Quinn, if I may add a point 10 to your (very meaningful) list: when pasting images, think of reducing the size (can edit simply the image ref by dividing a dimension by 2) to avoid huge images that clutter the screen. When you get an answer, please indicate if that solved the issue, if not explain what is not working. And don't forget to close the thread by marking the correct answer once you got it.
5
0
2.9k
May ’22
How to constrain a tableView to safe area ?
Here is the set up: I try to set a constraint for the top of tableView relative to safe area. No way by control-drag from tableView to Safe area. But if i create such a constraint for another object (here, like upperView) and then edit the constraint in Inspector, I can replace UpperView by tableView ; and get my constraint set. What am I missing here ?
2
0
846
Feb ’22
What is this view that appears floating over the tableView ?
I have a tableView inside a UIView in a VC. This VC is in a navigation view. It is a UIViewController, not a UITableViewController. The VC set up is this one: The issue: When I run app, there is a bar (full width, about 25 pixels high) appearing over the tableView at the bottom, hiding partially a cell (we see the (i) button nearly completely hidden). When scrolling tableView, this bar does not move and hides other cell. I looked at the view in debugger (I edited the content of cells): and found that the bar which is hiding comes from navigation controller: So 2 questions: what is this view ? How to avoid it coming over the table view ? I have a solution by replacing upperView by a header in tableView, but I would like to understand what goes on here.
5
0
1.4k
Feb ’22
App hangs when setting constraint to a very specific value (a width divided by 2).
I get a surprising crash when adapting constraints. Xcode 13.2.1 iOS 15.2 on simulator Here is the set up in storyboard: A subclass of UIView (PopoverView) to draw a popover like frame and label and button inside. PopoverView can set its arrow position all around, for instance on the right, so that popover will appear on the left of an object, or on the left, to appear on the right. Button tap is used to loop through the arrow position. I have defined constraints (and their IBOutlets), and notably for the centerX position of popoverView to centerX of the label. I adapt the value of the constraints in viewWillLayoutSubviews to position the popover in correct position relative to the label. Now the problem. To position the popover on the right of the label, I set its centerX constraint as follows in viewWillLayoutSubviews(): popoverCenterToLabelCenterConstraint.constant = (popoverLabel.frame.width + label.frame.width) / 2 That works OK To position the popover on the left of the label, I set its constraint as follows (offset the opposite value): popoverCenterToLabelCenterConstraint.constant = -(popoverLabel.frame.width + label.frame.width) / 2 I also tried: popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - label.frame.width / 2 App does not crash but hangs, apparently in an infinite loop. Idem if I divide by 2.0 instead of 2 : label.frame.width / 2.0 The width of the label, at this point of code, is 92.33333333333333 So I replaced by the value directly: popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - 46.2 and it works OK. Idem with 46.1 So the problem is not due to the position of popoverView If I replace the div by 2 by 2.01 : - popoverCenterToLabelCenterConstraint.constant = -popoverLabel.frame.width / 2 - label.frame.width / 2.01 it works !!!!!! Conclusion: it is the exact div by 2 that causes the hanging. What could be the reason for this strange behaviour ?
3
0
1.1k
Feb ’22
Several tags do not open anymore on the forum (today 1/29/2022)
Since a few hours, Sat 1/29/2022, several pages of the forum do not open, such as: https://developer.apple.com/forums/ https://developer.apple.com/forums/tags/ios all showing the same messages: Other tags open without problem. And those open with a payload: https://developer.apple.com/forums/?page=1&sortBy=lastUpdated https://developer.apple.com/forums/search/?q=column&page=1&sortBy=lastUpdated https://developer.apple.com/forums/tags/ios/?page=2 works, but page=1 doesn't Does anyone experience the same errors ? Conf: MacOS 12.2 (21D49) Safari Technology Preview Release 139 (Safari 15.4, WebKit 17613.1.14.41.3) But the pages open correctly on Firefox, Chrome. Does not open either on Safari Version 15.3 (17612.4.9.1.5) So issue is apparently on Safari probably not MacOS 12.2 (21D49) , nor on server side.
5
0
826
Jan ’22
Storyboard display issue
I get this weird behaviour of Xcode. Version 13.2.1 or 13.2 RC (may be other). In the storyboard I had a UITableViewController. As it does not give any flexibility to add other views in the VC, I created a new UIViewController, recreated the tableView inside as well as some other objects, added the new views I needed, redid all connections. Then I removed the UITableViewController. Everything works perfectly fine. But sometimes (cannot find any pattern for the cases), when opening the project, the old UITableViewController appears in Storyboard. The new UIViewController doesn't even seem to be here. When I select different VC in SB, no information in Identity inspector or other inspector. But it compiles and runs OK, using the new UIViewController. I cleaned build folder, closed Xcode, reboot the Mac, to no avail. Only way to get it solved was to close the SB and reopen it… Is there a cache somewhere in SB that is not cleared ?
1
0
1k
Jan ’22
repeatCount in UIViewPropertyAnimator
I have a func to flash a view a number of times and execute closure at the end. The following code with UIView.setAnimationRepeatCount works OK: animation occurs the requested number of times and afterEnd closure executes at the end. func flashIt(repeated: Int, cycleTime: Double, delayed: Double = 5.0, afterEnd: (() -> Void)? = nil) { if repeated < 0 { return } let initAlpha = self.alpha UIView.animate(withDuration: cycleTime, delay: delayed, options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat], animations: { UIView.setAnimationRepeatCount(Float(repeated)) self.alpha = 0.1 // Not 0.0, to allow user interaction }, completion: { (done: Bool) in self.alpha = initAlpha afterEnd?() } ) } To address UIView.setAnimationRepeatCount deprecation, I now try this (inspired by https://stackoverflow.com/questions/47496584/uiviewpropertyanimator-reverse-animation) func flashIt(repeated: Int, cycleTime: Double, delayed: Double = 5.0, afterEnd: (() -> Void)? = nil) { if repeated < 0 { return } let initAlpha = self.alpha let animator = UIViewPropertyAnimator(duration: cycleTime, curve: .linear) { self.alpha = 0.1 } animator.addCompletion { _ in let reverseAnimator = UIViewPropertyAnimator(duration: cycleTime, curve: .linear) { self.alpha = initAlpha } reverseAnimator.addCompletion { [self] _ in flashIt(repeated: repeated-1, cycleTime: cycleTime, delayed: 0) // without delay here } reverseAnimator.startAnimation() if repeated <= 1 { // 1 and not 0, otherwise an extra loop… afterEnd?() // Not called return } } animator.startAnimation(afterDelay: delayed) } The flash works, but afterEnd closure is never called. I've tried to call if repeated <= 1 { // 1 and not 0, otherwise an extra loop… afterEnd?() // Not called return } in other places, to no avail. What do I miss ? Is there a better and simpler way to have a RepeatCount with UIViewPropertyAnimator ?
3
0
1.3k
Dec ’21
UIApplication.openSettingsURLString does not work on iPadOS 15 simulator ?
The following code opens the app settings, including preferred language. func openSettings() { guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return } if UIApplication.shared.canOpenURL(settingsUrl) { UIApplication.shared.open(settingsUrl, completionHandler: nil) } } That works well in iOS (14.6 or 15.2), on iPadOS 14.4 ( both device and simulator) But on iPadOS 15.2 simulator, the preferred language setting for the app does not show. I noticed this in 2 different apps.
1
0
797
Dec ’21
SegmentedControl do not work correctly on iPhone 13Mini simulator
UISegmented controls seem not to work correctly in iPhone 13 Mini simulator. When tapping on a segment, control does not react before 30 to 40 s ; then it shows uncomplete redraw: I also noted similar lag in updating display when some label text changes. Configuration: MacOS 11.6.1 Xcode 13RC iOS 15.0 simulator. It works ok on a few other simulators I tested. I created an extremely simple project to reproduce: new project in Xcode 13RC added a segmentedControl at bottom of view, constrained to leading and trailing 0 to the safe area set selected color to red. run on iPhone 13 mini simulator I will test later with Xcode 13.2ß
1
0
841
Nov ’21
Change in Watch 7 in rounded corners of WKInterfaceLabel or WKInterfaceGroup
When testing in simulator with Xcode 13, I noted a subtle difference in the display of WKInterfaceLabel between Watch series 6 and series 7. WKInterfaceLabel is in a WKInterfaceGroup. On Series 7: the text Fast Driving is clipped with round corner at top and bottom On Series 6, round clipping is much less (noticeable on leading F and D) I could not find what parameter has changed in IB nor how to change this round corner value. Nor why such a change ?
3
0
1.7k
Oct ’21
Excluding activity types for UIActivityViewController: some are still present
I try to exclude some activities from UIActivity. It works as expected when exclusion is done directly with the activity, as with: UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop but not when activity is declared with an init as with: UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share"), So, with the following code: let excludedActivityTypes = [ UIActivity.ActivityType.message, UIActivity.ActivityType.airDrop, UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"), UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share") ]         let activityVC = UIActivityViewController(activityItems: [modifiedPdfURL], applicationActivities: nil)          activityVC.excludedActivityTypes = excludedActivityTypes message and airDrop do not show, but WhatsApp and IFTTT still show. I have tested with         activityVC.completionWithItemsHandler = { (activity, success, modifiedItems, error) in             print("activity: \(activity), success: \(success), items: \(modifiedItems), error: \(error)")         } that WhatsApp and IFTTT services are effectively the ones listed here. When selecting WhatsApp, print above gives: activity: Optional(__C.UIActivityType(_rawValue: net.whatsapp.WhatsApp.ShareExtension)), success: false, items: nil, error: nil
4
0
4.7k
Aug ’21
Perform action once UIActivityViewController has completed item action
I use UIActivityViewController to airDrop pdfFile (pdfURL) from iPhone to iMac. Works well, file is airDropped. let activityVC = UIActivityViewController(activityItems: [pdfURL], applicationActivities: nil) present(activityVC, animated: true, completion: nil) I want to customise it: limit services to AIrDrop and mail How can I exclude such services as WhatsApp, Notes… ? perform some action once the file has completed airDrop or once cancelled. I tried to implement with completionWithItemsHandler:         activityVC.completionWithItemsHandler = { (activity, success, items, error) in             print("Completed")         } This doesn't work, print is not executed. My ultimate goal is to close the activityVC automatically once action was completed, without need to tap close button. Should I define some content for applicationActivities ?
2
0
826
Aug ’21