Post

Replies

Boosts

Views

Activity

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
958
Feb ’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
1.1k
Mar ’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.5k
Mar ’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
3.3k
Jun ’22
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
5.2k
Jul ’22
Capturing the image read by QRCode
In this app I get access to QRCode. Reading works perfectly from the camera. Now I am struggling to get the image that was processed by the built in QRCode reader. I have found many hints on SO, but cannot make it work. Here is the code I have now. It is a bit long, I have to slit in 2 parts I looked at: // https://stackoverflow.com/questions/56088575/how-to-get-image-of-qr-code-after-scanning-in-swift-ios // https://stackoverflow.com/questions/37869963/how-to-use-avcapturephotooutput import UIKit import AVFoundation class ScannerViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { &#9;&#9;fileprivate var captureSession: AVCaptureSession! // use for QRCode reading &#9;&#9;fileprivate var previewLayer: AVCaptureVideoPreviewLayer! &#9;&#9; &#9;&#9;// To get the image of the QRCode &#9;&#9;private var photoOutputQR: AVCapturePhotoOutput! &#9;&#9;private var isCapturing = false &#9;&#9; &#9;&#9;override func viewDidLoad() { &#9;&#9;&#9;&#9;super.viewDidLoad() &#9;&#9;&#9;&#9;var accessGranted = false &#9;&#9;&#9; //&#9;switch AVCaptureDevice.authorizationStatus(for: .video) { // HERE TEST FOR ACCESS RIGHT. WORKS OK ; // But is .video enough ? &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if !accessGranted {&#9;return } &#9;&#9;&#9;&#9;captureSession = AVCaptureSession() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;photoOutputQR = AVCapturePhotoOutput() // IS IT THE RIGHT PLACE AND THE RIGHT THING TO DO ? &#9;&#9;&#9;&#9;captureSession.addOutput(photoOutputQR)&#9; // Goal is to capture an image of QRCode once acquisition is done &#9;&#9;&#9;&#9;guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { return } &#9;&#9;&#9;&#9;let videoInput: AVCaptureDeviceInput &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice) &#9;&#9;&#9;&#9;} catch {&#9;return } &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if (captureSession.canAddInput(videoInput)) { &#9;&#9;&#9;&#9;&#9;&#9;captureSession.addInput(videoInput) &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;failed() &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;let metadataOutput = AVCaptureMetadataOutput() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if (captureSession.canAddOutput(metadataOutput)) { &#9;&#9;&#9;&#9;&#9;&#9;captureSession.addOutput(metadataOutput) // SO I have 2 output in captureSession. IS IT RIGHT ? &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main) &#9;&#9;&#9;&#9;&#9;&#9;metadataOutput.metadataObjectTypes = [.qr]&#9;// For QRCode video acquisition &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;failed() &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) &#9;&#9;&#9;&#9;previewLayer.frame = view.layer.bounds &#9;&#9;&#9;&#9;previewLayer.frame.origin.y += 40 &#9;&#9;&#9;&#9;previewLayer.frame.size.height -= 40 &#9;&#9;&#9;&#9;previewLayer.videoGravity = .resizeAspectFill &#9;&#9;&#9;&#9;view.layer.addSublayer(previewLayer) &#9;&#9;&#9;&#9;captureSession.startRunning() &#9;&#9;} &#9;&#9; &#9;&#9;override func viewWillAppear(_ animated: Bool) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;super.viewWillAppear(animated) &#9;&#9;&#9;&#9;if (captureSession?.isRunning == false) { &#9;&#9;&#9;&#9;&#9;&#9;captureSession.startRunning() &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;override func viewWillDisappear(_ animated: Bool) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;super.viewWillDisappear(animated) &#9;&#9;&#9;&#9;if (captureSession?.isRunning == true) { &#9;&#9;&#9;&#9;&#9;&#9;captureSession.stopRunning() &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;// MARK: - scan Results &#9;&#9; &#9;&#9;func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) { &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;captureSession.stopRunning() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if let metadataObject = metadataObjects.first { &#9;&#9;&#9;&#9;&#9;&#9;guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return } &#9;&#9;&#9;&#9;&#9;&#9;guard let stringValue = readableObject.stringValue else { return } &#9;&#9;&#9;&#9;&#9;&#9;AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate)) &#9;&#9;&#9;&#9;&#9;&#9;found(code: stringValue) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;// Get image - IS IT THE RIGHT PLACE TO DO IT ? &#9;&#9;&#9;&#9;// https://stackoverflow.com/questions/37869963/how-to-use-avcapturephotooutput &#9;&#9;&#9;&#9;print("Do I get here ?", isCapturing) &#9;&#9;&#9;&#9;let photoSettings = AVCapturePhotoSettings() &#9;&#9;&#9;&#9;let previewPixelType = photoSettings.availablePreviewPhotoPixelFormatTypes.first! &#9;&#9;&#9;&#9;print("previewPixelType", previewPixelType) &#9;&#9;&#9;&#9;let previewFormat = [kCVPixelBufferPixelFormatTypeKey as String: previewPixelType, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; kCVPixelBufferWidthKey as String: 160, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; kCVPixelBufferHeightKey as String: 160] &#9;&#9;&#9;&#9;photoSettings.previewPhotoFormat = previewFormat &#9;&#9;&#9;&#9;if !isCapturing { &#9;&#9;&#9;&#9;&#9;&#9;isCapturing = true &#9;&#9;&#9;&#9;&#9;&#9;photoOutputQR.capturePhoto(with: photoSettings, delegate: self) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;dismiss(animated: true) &#9;&#9;} &#9;&#9; } extension ScannerViewController: AVCapturePhotoCaptureDelegate { &#9; &#9;&#9;func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { &#9;&#9;&#9; &#9;&#9;&#9;&#9;isCapturing = false &#9;&#9;&#9;&#9;print("photo", photo, photo.fileDataRepresentation()) &#9;&#9;&#9;&#9;guard let imageData = photo.fileDataRepresentation() else { &#9;&#9;&#9;&#9;&#9;&#9;print("Error while generating image from photo capture data."); &#9;&#9;&#9;&#9;&#9;&#9;return &#9;&#9;&#9;&#9;} &#9;&#9; } } I get the following print on console Clearly photo is not loaded properly Do I get here ? false previewPixelType 875704422 photo <AVCapturePhoto: 0x281973a20 pts:nan 1/1 settings:uid:3 photo:{0x0} time:nan-nan> nil Error while generating image from photo capture data.
4
0
6.1k
Jul ’22
NSKeyedUnarchiver validateAllowedClass error
I get this error in Xcode 14 / iOS 16 on device that I had not with previous versions. [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSNumber' (0x205da88f8) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.objects', even though it was not explicitly included in the client allowed classes set: '{(     "'NSDictionary' (0x205da1178) [/System/Library/Frameworks/CoreFoundation.framework]",     "'NSString' (0x205da8948) [/System/Library/Frameworks/Foundation.framework]" )}'. This will be disallowed in the future. The only places where I reference NSDictionary.self or NSString.self or NSNumber.self for allowed classes are: @objc class MyClass : NSObject, NSSecureCoding {       required init(coder decoder: NSCoder) {        let myObject = decoder.decodeObject(of: [MyClass.self, NSNumber.self, NSArray.self, NSDictionary.self, NSString.self], forKey: myKey) as? [SomeClass] ?? []     } and in another class class Util { // in a class func:     let data = try Data(contentsOf: fileURL)     guard let unarchived = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: data) else { return nil } I do not understand what NS.objects refers to. I tried to add NSObject.self in        let myObject = decoder.decodeObject(of: [MyClass.self, NSNumber.self, NSArray.self, NSDictionary.self, NSString.self, NSObject.self], forKey: myKey) as? [SomeClass] ?? [] but that gave even more warnings: [Foundation] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:]: NSSecureCoding allowed classes list contains [NSObject class], which bypasses security by allowing any Objective-C class to be implicitly decoded. Consider reducing the scope of allowed classes during decoding by listing only the classes you expect to decode, or a more specific base class than NSObject. This will become an error in the future. Allowed class list: {(     "'NSNumber' (0x205da88f8) [/System/Library/Frameworks/Foundation.framework]",     "'NSArray' (0x205da1240) [/System/Library/Frameworks/CoreFoundation.framework]",     "'NSObject' (0x205d8cb98) [/usr/lib]",     "'NSDictionary' (0x205da1178) [/System/Library/Frameworks/CoreFoundation.framework]",     "'MyClass.self' (0x1002f11a0) [/private/var/containers/Bundle/Application/5517240E-FB23-468D-80FA-B7E37D30936A/MyApp.app]",     "'NSString' (0x205da8948) [/System/Library/Frameworks/Foundation.framework]" Another warning refers to NS.keys: 2022-09-16 16:19:10.911977+0200 MyApp[4439:1970094] [general] *** -[NSKeyedUnarchiver validateAllowedClass:forKey:] allowed unarchiving safe plist type ''NSString' (0x205da8948) [/System/Library/Frameworks/Foundation.framework]' for key 'NS.keys', even though it was not explicitly included in the client allowed classes set: '{(     "'NSDictionary' (0x205da1178) [/System/Library/Frameworks/CoreFoundation.framework]" )}'. This will be disallowed in the future. I do not understand what NS.keys refers to. What additional class types should I add ?
4
2
4.7k
Sep ’22
Failed to install WatchOS 9.1 simulator runtime in Xcode 14.2
I installed Xcode 14.2 (in parallel with other versions of Xcode with different names) on MBP MacOS 12.6.2. Il works OK except when trying to use WatchOS simulator. When I select a WatchOS target and then look for simulator, none is installed. I get an item in menu proposing to GET 9.1. I downloaded. But at the end of download, installation failed with the message that installation of watchOS 9.1 simulator runtime failed in CoreSimulator. I tried the solution proposed here, to no avail. https://stackoverflow.com/questions/74096242/unable-to-select-device-for-watchos-app-in-xcode Note: installation on an iMac running 12.6.2 and Xcode 14.2 shows a long list of simulators:
1
0
1.7k
Dec ’22
Remote control for iPad from BLE device
I need to implement a remote control for a SwiftUI app running on iPad. I would need to handle 2 different events like Start / Stop. On software side, I plan to use .onReceive to listen to BLE device. So my questions: I need realtime reaction (a few 1/100 s max) can any BLE remote control do the job ? If anyone has tested some low cost remote, I am interested to know. Or should I look for Homekit solutions ? Or use an iPhone as remote controller ?
0
0
876
Dec ’22
Button behaviour changes if position(x:y)
With this code, button is at the center of the view and message is logged only when tapping in the button 1. struct ContentView: View { 2. var body: some View { 3. 4. ZStack { 5. Button(action: { 6. print("Touched") 7. }) { 8. Image(systemName: "square.split.diagonal.2x2") 9. .font(.system(size: 24)) 10. .foregroundColor(.black) 11. // .position(x: 12, y: 12) 12. } 13. 14. } 15. .frame(width: 300, height: 300) 16. .background(Color.yellow) 17. } 18. } But if I uncomment line 11, the message is logged on tap anywhere in the view. How is it position() changes the behaviour ?
3
0
1.1k
Dec ’22
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.4k
Jan ’23
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.9k
Jan ’23