Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Post

Replies

Boosts

Views

Activity

On iOS 17, UICollectionView updates trigger a resignFirstResponder call even when the cell with the text input is unaffected
I have a view with search functionality implemented with a UICollectionView. In a cell in section 0 there's a UITextField used for input. Changes in it trigger an update, during which collectionView.performBatchUpdates is called, with the updates block containing insertSections, deleteSections and reloadSections calls that only affect higher section indices. On previous iOS versions there are no issues here, but starting on iOS 17, keyboard drops after every character entered. Adding a symbolic breakpoint on -[UIResponder resignFirstResponder] results in a break on the collectionView.performBatchUpdates call with the following UIKit methods in the stack trace above it: #0 0x00000001852e5b78 in -[UIResponder resignFirstResponder] () #1 0x00000001855d6bcc in -[UITextField resignFirstResponder] () #2 0x0000000184a38f34 in -[UICollectionView _resignOrRebaseFirstResponderViewWithIndexPathMapping:] () #3 0x0000000184a37394 in -[UICollectionView _updateWithItems:tentativelyForReordering:propertyAnimator:collectionViewAnimator:] () #4 0x0000000184a309f0 in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] () #5 0x0000000184a3a808 in -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:animationHandler:] ()
4
1
1.1k
Nov ’23
AR Quick Look in swift ui
HI, I'm new to IOS Dev. I am developing an app with AR function. I found there are a few tutorials about AR Quick Look. However, they're all use storyboard. Is there any way to use swift ui to demonstrate AR Quick Look. ContentView.swift import SwiftUI //import QuickLook //import ARKit struct ContentView: View { @State private var isPresented = false var body: some View { VStack { Button { isPresented = true print("click") } label: { Text("Click to AR") .font(.title) .fontWeight(.bold) .padding() .background() .cornerRadius(16) } .sheet(isPresented: $isPresented) { ARView() } .padding() } } } #Preview { ContentView() } ARView.swift import SwiftUI struct ARView: UIViewControllerRepresentable { func makeUIViewController(context: Context) -> QuickViewController { QuickViewController() } func updateUIViewController(_ uiViewController: QuickViewController, context: Context) { uiViewController.presentARQuickLook() } typealias UIViewControllerType = QuickViewController } QuickViewController.swift import UIKit import QuickLook import ARKit class QuickViewController: UIViewController, QLPreviewControllerDelegate, QLPreviewControllerDataSource { // 有幾個模型要呈現 func numberOfPreviewItems(in controller: QLPreviewController) -> Int { return 1 } // 顯示模型 func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { let url = Bundle.main.url(forResource: "bear", withExtension: "usdz")! // Load file url let preview = ARQuickLookPreviewItem(fileAt: url) return preview } func presentARQuickLook() { let previewController = QLPreviewController() previewController.dataSource = self present(previewController, animated: true) print("Open AR model!") } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }
0
0
841
Nov ’23
Document Picker does not work on device
I have a problem with Xcode version 15.0.1: I have programmed a DocumentPicker in Swift UI to load a document from my own cloud into the app. When I run the app, it works fantastic with the simulator, but it doesn't work with my device. I always get the following error message: file is not reachable. Ensure file URL is not a directory, symbolic link, or invalid url. As I said, when I run the code in the simulator, it works fine. I am using IOS 17.2 Here is the code. import SwiftUI import MobileCoreServices import Firebase import FirebaseStorage import CoreData import UniformTypeIdentifiers struct DocumentPickerView: UIViewControllerRepresentable { @Binding var fileContent : String @Binding var nameContent : String @Binding var showqr : Bool @Binding var documentURL: URL? @Binding var alert: Bool // @Binding var webViewURL : URL func makeCoordinator() -> Coordinator { Coordinator(self) } func makeUIViewController(context: Context) -> UIDocumentPickerViewController { // let picker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) let types: [UTType] = [UTType.content] let picker = UIDocumentPickerViewController(forOpeningContentTypes:types) picker.allowsMultipleSelection = false picker.delegate = context.coordinator return picker } func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {} class Coordinator: NSObject, UIDocumentPickerDelegate { var parent: DocumentPickerView init(_ parent: DocumentPickerView) { self.parent = parent } func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { if let selectedURL = urls.first { parent.documentURL = selectedURL parent.uploadToFirebase(selectedURL) } } } func uploadToFirebase(_ fileURL: URL) { let storage = Storage.storage() let storageRef = storage.reference() let fileRef = storageRef.child(fileURL.lastPathComponent) // if FileManager.default.fileExists(atPath: fileURL.path){ // print("File Existiert:\(fileURL)") // } else { // print("File Existiert nicht") // } _ = fileRef.putFile(from: fileURL, metadata: nil){ (metadata, error) in if let error = error { print("Fehler beim Hochladen der Datei: \(error.localizedDescription)") } else { print("Datei erfolgreich hochgeladen!") // Rufen Sie die Download-URL für die hochgeladene Datei ab fileRef.downloadURL { (url, error) in if let error = error { alert = true print("Fehler beim Abrufen der Download-URL: \(error.localizedDescription)") } else { if let downloadURL = url { print("Download-URL: \(downloadURL)") self.fileContent = "\(downloadURL)" self.showqr = true } } } } } } }
2
0
1.2k
Nov ’23
iOS: Get next word predictions
Does iOS provide an API for getting text predictions based on previous text? I tried with UITextChecker.completions as such let str = "Hello" let range = NSMakeRange(str.utf16.count, 0) let tc = UITextChecker() let completions = tc.completions(forPartialWordRange: range, in: str, language: "en-US") print(completions) However, this only works for completing words, not sentences. Does iOS have a way of doing this? I read somewhere that macOS does. If not, what workarounds/alternatives would you recommend?
0
0
685
Nov ’23
iOS 17 UIImageView tintColor issue
Applying color picked from UIColorPickerViewController to UIImageview's tintColor(a color having kCGColorSpaceModelRGB ColorSpace), then getting tintColor from that same UIImageView is always giving me gray color(a color having uiextendedgraycolorspace ColorSpace), this issue occured only in iOS 17 What can be the issue and please help me to solve it.
2
0
624
Nov ’23
SwiftUI Third Party Keyboard
Hello. I am developing an app that helps people with language issues communicate and for that I thought I could do a custom keyboard for them. I was wondering if there is a way of doing a 3rd party keyboard using SwiftUI (little to no UIKit) and if so, where can I find documentation/tutorials. I have looked with no success. Additionally, can we use a PKCanvasView inside of keyboards (ie, is there any restriction/policy)? I intend to use it so that users can draw the words they're looking for (I already have the model and know how to come up with the suggestions and everything) Thanks a lot!
0
0
643
Nov ’23
There are a lot of crashes in iOS17 and above
Hardware Model: iPhone15,3 Process: 甘草医生 [2305] Path: /private/var/containers/Bundle/Application/18AF408C-3B8B-4829-8621-4CCC16013765/甘草医生.app/甘草医生 Identifier: com.gancaoDoctor.doctor Version: 4.5.6 (45600) AppStoreTools: 15A240a AppVariant: 1:iPhone15,3:16 Code Type: ARM-64 (Native) Role: unknown Parent Process: launchd [1] Coalition: com.gancaoDoctor.doctor [1214] Date/Time: 2023-10-28 21:17:48.9795 +0800 Launch Time: 2023-10-28 21:10:32.0919 +0800 OS Version: iPhone OS 17.1 (21B74) Release Type: User Baseband Version: 2.10.03 Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000524f185b80 Exception Codes: 0x0000000000000002, 0x000000524f185b80 VM Region Info: 0x524f185b80 is in 0x524f184000-0x7000000000; bytes after start: 7040 bytes before end: 127522022527 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL commpage (reserved) 1000000000-524f184000 [265.2G] ---/--- SM=NUL ...(unallocated) ---> GPU Carveout (reserved) 524f184000-7000000000 [118.8G] ---/--- SM=NUL ...(unallocated) UNUSED SPACE AT END Triggered by Thread: 0 Thread 0 name: Thread 0 Crashed: 0 libobjc.A.dylib 0x00000001936433cc class_getMethodImplementation + 56 (objc-class.mm:702) 1 Foundation 0x000000019a230c74 _NSKVONotifyingOriginalClassForIsa + 32 (NSKeyValueObserverNotifying.m:950) 2 Foundation 0x000000019a230924 _NSKeyValueObservationInfoGetObservances + 280 (NSKeyValueObservationInfo.m:820) 3 Foundation 0x000000019a22fddc NSKeyValueWillChangeWithPerThreadPendingNotifications + 232 (NSKeyValueObserving.m:1199) 4 QuartzCore 0x000000019c9647a8 CA::Display::Display::update() + 2564 (CADisplay.mm:2904) 5 QuartzCore 0x000000019c9c8658 invocation function for block in ensure_displays() + 136 (CADisplay.mm:6040) 6 libsystem_notify.dylib 0x00000001c5efdbec ___notify_dispatch_local_notification_block_invoke + 72 (notify_client.c:2044) 7 libdispatch.dylib 0x00000001a3240250 _dispatch_block_async_invoke2 + 148 (queue.c:555) 8 libdispatch.dylib 0x00000001a3231300 _dispatch_client_callout + 20 (object.m:561) 9 libdispatch.dylib 0x00000001a323f998 _dispatch_main_queue_drain + 984 (queue.c:7813) 10 libdispatch.dylib 0x00000001a323f5b0 _dispatch_main_queue_callback_4CF + 44 (queue.c:7973) 11 CoreFoundation 0x000000019b2ab20c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1780) 12 CoreFoundation 0x000000019b2a7f18 __CFRunLoopRun + 1996 (CFRunLoop.c:3149) 13 CoreFoundation 0x000000019b2a7668 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420) 14 GraphicsServices 0x00000001de6725ec GSEventRunModal + 164 (GSEvent.c:2196) 15 UIKitCore 0x000000019d6c4294 -[UIApplication _run] + 888 (UIApplication.m:3685) 16 UIKitCore 0x000000019d6c38d0 UIApplicationMain + 340 (UIApplication.m:5270) 17 甘草医生 0x00000001049b64a8 main + 168 (main.m:22) 18 dyld 0x00000001bdcfadcc start + 2240 (dyldMain.cpp:1269)
0
0
318
Nov ’23
-[UINavigationController pushViewController:transition:forceImmediate:]
Fatal Exception: NSInvalidArgumentException <UIPrintPanelNavigationController: 0x144010a00> is pushing the same view controller instance (<UIPrinterBrowserViewController: 0x142854400>) more than once which is not supported and is most likely an error in the application : com.myapp.myapp Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0xec870 __exceptionPreprocess 1 libobjc.A.dylib 0x2bc00 objc_exception_throw 2 UIKitCore 0xcb284 -[UINavigationController pushViewController:transition:forceImmediate:] 3 UIKitCore 0xca398 -[UINavigationController pushViewController:animated:] 4 PrintKitUI 0x45024 -[UIPrintPanelNavigationController pushViewController:animated:] 5 UIKitCore 0x129b78 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] 6 UIKitCore 0x129680 -[_UIViewControllerTransitionContext _runAlongsideCompletions] 7 UIKitCore 0x128d10 -[_UIViewControllerTransitionContext completeTransition:] 8 UIKitCore 0x7a3d48 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_5 9 UIKitCore 0x84a38 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ 10 UIKitCore 0x841d0 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] 11 UIKitCore 0x83848 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] 12 UIKitCore 0x65aa4 -[UIViewAnimationState animationDidStop:finished:] 13 UIKitCore 0x65bb8 -[UIViewAnimationState animationDidStop:finished:] 14 QuartzCore 0x72098 run_animation_callbacks(void*) 15 libdispatch.dylib 0x4300 _dispatch_client_callout 16 libdispatch.dylib 0x12998 _dispatch_main_queue_drain 17 libdispatch.dylib 0x125b0 _dispatch_main_queue_callback_4CF 18 CoreFoundation 0x3720c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ 19 CoreFoundation 0x33f18 __CFRunLoopRun 20 CoreFoundation 0x33668 CFRunLoopRunSpecific 21 GraphicsServices 0x35ec GSEventRunModal 22 UIKitCore 0x22c2b4 -[UIApplication _run] 23 UIKitCore 0x22b8f0 UIApplicationMain 24 MyApp 0x4a940 main + 14 (main.m:14) 25 ??? 0x1ac55adcc (Missing) I found this crash in Firebase crashlytics. This is device info Model:iPad Air (5th generation) Version:17.1.1 Orientation:Landscape Please help me to findout the root cause of the crash and possible solution. I have tried to reprduce the crash but didn't reproduce.
1
0
950
Nov ’23
UIContentUnavailableConfiguration and Accessibility VoiceOver
I have been implementing UIContentUnavailableConfigurations in my app and I've noticed that when contentUnavailableConfiguration changes via func updateContentUnavailableConfiguration(using state: UIContentUnavailableConfigurationState) VoiceOver does not focus on the content of the UIContentUnavailableConfiguration. It either focuses on the NavBar back button or on a subview behind the content unavailable overlay. I've looked at using UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: nil) but I can't find an accessibility element to provide as an argument. Is there a way to focus VoiceOver on the UIContentUnavailableView when contentUnavailableConfiguration changes?
0
0
293
Nov ’23
*** Assertion failure in -[_UISystemBackgroundView _internalSubviewsOfType:], _UISystemBackgroundView.m:133
Our application was working fine in iOS 16, but after upgrading to iOS 17.1.1, we see a 100% reproducible crash when generating a cell in the [UITableViewDataSource tableView: cellForRowAtIndexPath:] callback for a particular table. I've only found a single table so far where it crashes. This is the line of code where it crashes: ItemContentTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath]; The crash occurs on the first call. Since it only crashes in this one table, I imagine it's somehow related to the particulars of the cell content layout, but as far as I can see, there's nothing spectacular going on there. Any ideas?? Thanks.
4
0
748
Nov ’23
Share submenu in Mac Catalyst and UICommandTagShare
With Mac Catalyst, in Big Sur and Monterey, you could use UICommandTagShare as the property list for a UICommand in combination with activityItemsConfiguration and itemProvidersForActivityItemsConfiguration to allow a "Share" submenu to appear in a menu in your app (for instance, under the File menu like many other apps). Starting in Ventura, this submenu no longer appears with that same code, and instead the UICommandTagShare command in the menu now just displays "Share" with no submenu, which triggers a UIActivityViewController to appear in the main window. Is there any way to still allow a Share submenu to work in Ventura and beyond with Mac Catalyst? Thanks so much for any help!
1
1
571
Dec ’23
Changing presentation style crashes app
Hello! I've been digging into this for a little bit now, and am hitting something of a wall. Our app is crashing occasionally, and googling the crash yields literally 0 results. Tl;dr: Something related to adaptivePresentationStyle(for:traitCollection:) is resulting in our app crashing. Context In our app, we have a custom UIPresentationController that we use to present a small sheet of content overlaying other app content - similar to a UISheetPresentationController with a medium-ish size. So we have a custom UIViewController to present, and it conforms to the UIAdaptivePresentationControllerDelegate protocol. We also have custom present and dismiss animators. The crash However, we seem to be running into a really odd crash. I've attached a crash report as well, but here's what one sees in xcode on reproducing the crash: The _computeToEndFrameForCurrentTransition block is nil inside the _transitionViewForCurrentTransition block, value of outerStrongSelf currently : <XxxYyyyyyZzz.PopupPresentationController: 0x12d017a40>. This most likely indicates that an adaptation is happening after a transtion cleared out _computeToEndFrameForCurrentTransition. Captured debug information outside block: presentationController : <XxxYyyyyyZzz.PopupPresentationController: 0x12d017a40> presentedViewController : <XxxYyyyyyZzz.SomeViewController: 0x12d03a690> presentingViewController : <UINavigationController: 0x12a817400> 2023-09-25_08-02-33.6523_-0500-7d355cd4a86427213389765ef070a777c4b4aaa3.crash Whenever we present one of these view controllers, things work just fine. When we try to present another one though, if someone is aggressively changing the phone orientation, the app crashes. This crash occurs somewhere in between dismissing the old VC and presenting the new one. It occurs before I ever hit any breakpoints in the "present" animator for the second view controller. I've narrowed things down a bit, and by commenting out our implementation of adaptivePresentationStyle(for:traitCollection:), the crash can't be reproduced anymore. The downside there being that the app no longer functions how we want it to. Our definition of that function (which causes crashes) looks like this: public func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { guard forceUsingFullScreenIfCompact else { return .none } return traitCollection.verticalSizeClass == .compact ? .overFullScreen : .none } A bit more testing, and it seems like if that function returns the same thing consistently, nothing crashes. Are we not allowed to put conditional logic in this function? In the crash, we can see that it occurs due to a failing assertion internal to UIPresentationController: Last Exception Backtrace: 0 CoreFoundation 0x1afa28cb4 __exceptionPreprocess + 164 (NSException.m:202) 1 libobjc.A.dylib 0x1a8abc3d0 objc_exception_throw + 60 (objc-exception.mm:356) 2 Foundation 0x1aa1b2688 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 172 (NSException.m:251) 3 UIKitCore 0x1b1d05610 __80-[UIPresentationController _initViewHierarchyForPresentationSuperview:inWindow:]_block_invoke + 2588 (UIPresentationController.m:1594) 4 UIKitCore 0x1b21f1ff4 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_3 + 300 (UIPresentationController.m:1228) The question This all leads us to wonder if we're doing something wrong, or if there could be a bug in one of the iOS APIs that we're consuming. Thus, posting here. Does anyone have any insight into how this could be occurring, or has seen this before and has ideas? Thanks! Miscellaneous info We target iOS 14+ We've seen this issue in debug and release builds from Xcode 14 and 15 We see the issue on users with iOS 15+, though it could be occurring on 14 in just incredibly low numbers This is a re-post of https://developer.apple.com/forums/thread/738257, because I accidentally closed that out as resolved
4
2
798
Dec ’23
Help with crash in objc_msgSend (no app code in stack trace)
Hello, I am attempting to track down a crash that isn't giving me a lot of information (crash log included below). Here is what I know so far: According to Apple documentation, a crash in objc_msgSend is due to a zombie object. So I have been trying to recreate the crash with zombies enabled, without success. The address of the object being messaged is 0x0000000000000010, a suspect value. It's always 0x10, across thousands of crash reports with slightly differing stack traces and circumstances. That makes me wonder if the runtime is trying to tell me something with that address, but I have been unable to find any documentation to that effect. We have internal analytics that suggest that the crash always happens after the user activates the system PIP video player, and usually also after backgrounding the app. It is also common (though not universal) that the crash occurs after the user has paused the video (and sometimes resumed it). This post is a bit of a Hail Mary; I'm hoping that maybe someone on here will see something I missed, because I have exhausted most of my own avenues of investigation. Many thanks for any help you can provide. 2023-11-30_07-16-00.4347_-0800-ffd5dc1a3d2ca628e1761ccfec5fe79f223d099e.crash
3
0
1.8k
Dec ’23
MFMessageComposeViewController cannot send special characters via iOS 17
I have a text in the application that comes with special characters (the text is written in French) that I want to send using MFMessageComposeViewController. I define the text in the body field: messageComposeVC.body = body and call to present the message compose like that : UIApplication.topViewController()?.present(messageComposeVC, animated: true, completion: nil) The message/imessage open and display the preview with the text i defined. But, since the upgrade of the iPhone to ios 17 it stopped working, when i send the message the message was not send and I received a message that the message failed. I also tested on ios 16 - it works great. Any idea how i can fix it?
0
0
851
Dec ’23
How to disable scroll animation for UITextField?
Yes, I mean UITextField. Howdy, Is there a way to disable the animation that occurs to a UITextField with long content after it becomes first responder? Specifically the one that sort of slow scrolls to the end of the content. Here's a video of the animation I am trying to describe https://www.youtube.com/watch?v=9l2tUrxW_qY . Notice how the textfield transitions from "a" to "." as it moves to the end of the content? Ideally, I would like the UITextField to simply appear on the screen like it does in the final frame of the animation, showing the final part of the content. Thanks, smkuehnhold
0
0
404
Dec ’23