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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

Apple Maps annotations and markers
In Apple's Maps app, an annotation is made up of a circle shape or rounded rectangles with a glyph-image. When selecting an annotation, the annotation animates into a balloon marker (see attached GIF). How does Apple Maps solve this - from custom annotation to balloon marker with spring animation? I switched my Maps implementation from SwiftUI to UIKit with a UIViewRepresentable to support annotation clustering - and it works beautifully. But how to subclass an MKAnnotationView (or MKMarkerAnnotationView <- the balloon) to enable selection and animation as in Apple Maps? MKMarkerAnnotationView only show balloon markers and I tried everything inside MKAnnotationView (CALayer, etc.)
1
0
225
3w
[Bug] UIDocumentPickerViewController Crash: “DocumentManager service tried to send a message to a deallocated host proxy”
We are experiencing an issue where UIDocumentPickerViewController causes an uncaught exception when it is dismissed under certain conditions. The error appears as: <NSXPCConnection: 0x301ac7660> connection from pid 2075 on anonymousListener or serviceListener: Warning: Exception caught during invocation of selector _updateRemoteBarButtonFrames:forUUID:, dropping incoming message and invalidating the connection. Exception: DocumentManager service tried to send a message to a deallocated host proxy DocumentManager service tried to send a message to a deallocated host proxy ( 0 CoreFoundation 0x0000000186c2a608 0013A8B1-2524-3534-B5BA-681AAF18C798 + 185864 1 libobjc.A.dylib 0x00000001841a5244 objc_exception_throw + 88 2 Foundation 0x000000018602eec0 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 8576704 3 DocumentManager 0x00000002177cf7b8 0BAEFA1B-BD6D-3472-A1B3-6E09F5DE54F2 + 96184 4 CoreFoundation 0x0000000186c2d078 0013A8B1-2524-3534-B5BA-681AAF18C798 + 196728 5 CoreFoundation 0x0000000186c2cef0 _CF_forwarding_prep_0 + 96 6 Foundation 0x00000001858b8d8c E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 753036 7 Foundation 0x00000001858b7fc8 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 749512 8 Foundation 0x00000001858b7220 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 746016 9 Foundation 0x00000001858b70d8 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 745688 10 libxpc.dylib 0x00000002119f1a50 527F7127-9586-32C8-9D8B-2972D39EAD7A + 72272 11 libxpc.dylib 0x00000002119f35cc 527F7127-9586-32C8-9D8B-2972D39EAD7A + 79308 12 libdispatch.dylib 0x000000010160a638 _dispatch_client_callout4 + 20 13 libdispatch.dylib 0x0000000101627eac _dispatch_mach_msg_invoke + 512 14 libdispatch.dylib 0x000000010161226c _dispatch_lane_serial_drain + 352 15 libdispatch.dylib 0x0000000101628ea4 _dispatch_mach_invoke + 492 16 libdispatch.dylib 0x000000010161226c _dispatch_lane_serial_drain + 352 17 libdispatch.dylib 0x0000000101613290 _dispatch_lane_invoke + 460 18 libdispatch.dylib 0x00000001016206fc _dispatch_root_queue_drain_deferred_wlh + 328 19 libdispatch.dylib 0x000000010161fd0c _dispatch_workloop_worker_thread + 580 20 libsystem_pthread.dylib 0x0000000211998680 _pthread_wqthread + 288 21 libsystem_pthread.dylib 0x0000000211996474 start_wqthread + 8 ) *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'DocumentManager service tried to send a message to a deallocated host proxy' Steps to Reproduce Present a UIDocumentPickerViewController inside a custom UIViewController. Dismiss the parent UIViewController before UIDocumentPickerViewController is fully visible. Swipe down or press the “Cancel” button in the picker. Occasionally, the system forcefully terminates the view service, causing a crash. Workarounds Tried (Unsuccessful) Using UIAdaptivePresentationControllerDelegate – Not Called for UIDocumentPickerViewController. Using viewDidDisappear to clean up – Not Called when the system terminates the picker. Forcing dismissal before presenting a new picker Reference to Line 42 in DOCRemoteViewController.m From the error traceback, we see a reference to DOCRemoteViewController.m line 42, which strongly suggests that UIDocumentPickerViewController relies on a background process to manage its lifecycle. Since we don’t have access to Apple’s private code, we assume that the DocumentManager service is trying to send a message to an already deallocated instance of UIDocumentPickerViewController, leading to a crash. One of the example wrapper implementation of us: class DocumentPickerViewController: UIViewController, UIDocumentPickerDelegate { private var picker: UIDocumentPickerViewController? weak var delegate: UIDocumentPickerDelegate? override func viewDidLoad() { super.viewDidLoad() print("📄 DocumentPickerViewController - viewDidLoad() called") setupDocumentPicker() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) print("📄 DocumentPickerViewController - viewDidAppear() called") } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) print("📄 DocumentPickerViewController - viewWillAppear() called") } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) print("📄 DocumentPickerViewController - viewWillDisappear() called") } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) print("📄 DocumentPickerViewController - viewDidDisappear() called") } deinit { print("🗑 DocumentPickerViewController - deinit() called") } // MARK: - Setup Document Picker private func setupDocumentPicker() { picker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf]) picker?.delegate = self picker?.allowsMultipleSelection = false picker?.modalPresentationStyle = .formSheet if let picker = picker { present(picker, animated: false) { print("📄 Document Picker fully presented") } } } // MARK: - UIDocumentPickerDelegate Methods func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { print("✅ User selected document(s): \(urls)") delegate?.documentPicker?(controller, didPickDocumentsAt: urls) dismissSelf() } func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { print("❌ User cancelled document selection") delegate?.documentPickerWasCancelled?(controller) dismissSelf() } private func dismissSelf() { DispatchQueue.main.async { [weak self] in self?.dismiss(animated: true) } } } And logs for this implementation: 📄 Document Picker fully presented 📄 DocumentPickerViewController - viewDidAppear() called ❌ User cancelled document selection The view service did terminate with error: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method} 📄 DocumentPickerViewController - viewDidLoad() called 📄 Document Picker fully presented 📄 DocumentPickerViewController - viewDidAppear() called would appreciate any workarounds from the community to prevent crashes related to this issue!
3
0
326
3w
Extending iOS screen to an external display
I understand two key concepts from desktop platforms: Screen Mirroring – The same content is displayed on both the primary and external screens. Screen Extension – The external display shows different content that complements what's on the main screen. My question pertains to the second point: Is it possible to extend the display on iOS and iPadOS devices? I'm referring to this Apple documentation, which explains how to extend content from an iOS/iPadOS device to an external display. I tested this in a sample iOS Xcode project. In the iOS Simulator, I was able to detect an "external display" and present a separate UIWindow on it. However, when I tried the same on a real device (iPhone 15 connected to a MacBook Pro via cable), the external display connection was not detected. I’d like to confirm whether screen extension is possible on a real iOS device. From my research, it appears that extension is only supported on iPadOS via Stage Manager, but I want to verify if there’s any way to achieve this on an iPhone. If so, are there any known apps that currently utilize extended display functionality on iOS? If extension is not possible on iOS, what does the documentation mentions iOS?
1
0
241
3w
labels appear as dimmed in UIView
In this setup, label do not show properly because of the textColor. Labels are defined in IB, in the following hierarchy: ViewController View Label 1 scrollView View Button Label 2 Buttons show properly, but labels, even though defined with default label color appear as if their alpha was 0.2. It is even worse in dark mode: I have checked the settings for the label and did not find anything anormal: I have tried to change label color to system.gray 2, to no avail. If I change to red, does not show in red in IB. Problem appears for both Label 1 (at the top level in the view) and Label 2
1
0
218
3w
Do the coordinates obtained by scanning a QR code with VNDetectBarcodesRequest match the coordinates of the finder pattern?
I am creating an application that uses VNDetectBarcodesRequest to read QR codes from images and adjust the image orientation to match that of the QR code finder pattern. The QR code was successfully read, and the coordinates of the QR code were obtained.Upon checking the obtained topLeft, topRight, and bottomLeft coordinates, they always seem to match the topLeft, topRight, and bottomLeft coordinates of the finder pattern. Is it specified that the coordinates of topLeft, topRight, and bottomLeft obtained with VNDetectBarcodesRequest match the topLeft, topRight, and bottomLeft of the finder pattern? Or do they just happen to match? I would appreciate it if you could tell me if the matching of coordinates is a specification. Thank you for your help.
0
0
206
3w
WKWebView: Select Text and scroll beyond what's visible
Prime Objective I am trying to have a scroll view with a fixed header, a fixed footer, and a WKWebView in between. Using JavaScript, the height of the webView is determined and set to be large enough to hold the entire content. The Problem When selecting text on the webView, the view does not scroll when the edges are reached (this works if the webView is shown without being embedded in a Scroll view, or if it is the last element) What did I try? I tried reading the scroll view, or adding a gesture recognizer, but all of that does not work because the selection is essentially a system task Sourcecode Sourcecode to demonstrate the issue can be found on GitHub
1
0
200
4w
tvOS: Search Keyboard Unresponsive After Dismissing Custom Controller with Embedded TVDigitEntryViewController
Description I'm developing a tvOS application where I utilize a UISearchController embedded within a UISearchContainerViewController for search functionality. In a particular flow, a custom view controller contains a TVDigitEntryViewController as a child, with its modalPresentationStyle set to .blurOverFullScreen. The issue arises when a user initiates the PIN entry but decides to cancel and return to the search interface without entering a PIN. Upon returning, the search keyboard is no longer visible, and attempts to focus or interact with it are unsuccessful. Steps to Reproduce Initialize and present a UISearchContainerViewController that contains a UISearchController with a results view controller. Within the search results, present a custom view controller containing TVDigitEntryViewController as a child, setting its modalPresentationStyle to .blurOverFullScreen. Dismiss the custom view controller without entering a PIN (e.g., by pressing the Menu button on the remote). Observe that upon returning to the search interface, the keyboard is missing, and focus interactions are unresponsive. Observed Behavior After dismissing the custom view controller with TVDigitEntryViewController, the search keyboard does not reappear, and the focus system seems to lose track of the search input field. Expected Behavior The search keyboard should remain visible and functional after dismissing the custom view controller, allowing users to continue their search without interruption. Additional Context I have reviewed the TVDigitEntryViewController documentation (developer.apple.com) and related discussions on the Apple Developer Forums but have not found a solution to this specific issue. Questions Has anyone encountered a similar issue or have insights into why the search keyboard becomes unresponsive after dismissing a .blurOverFullScreen modal with a child TVDigitEntryViewController? Are there recommended practices to ensure the search keyboard remains active and focusable after such modal presentations? Any guidance or suggestions would be greatly appreciated. Thank you!
3
0
262
4w
collectionView(_:shouldBeginMultipleSelectionInteractionAt:) triggered by trackpad click
In my collection view I have allowsSelection, allowsSelectionDuringEditing, and allowsMultipleSelectionDuringEditing set to true. In my delegate's collectionView(_:shouldBeginMultipleSelectionInteractionAt:) I return true unconditionally, getting me the desired behavior of triggering edit mode with a two-finger swipe. So far so good. The problem is that collectionView(_:shouldBeginMultipleSelectionInteractionAt:) is also called on a single-finger click from a trackpad. Tapping one of my cells is supposed to open a sub-screen, so with this happening there's no way to navigate my screen using a trackpad. This also goes against the documentation, which says this delegate method is supposed to get called because of a two-finger swipe. Is there a way to keep that call from happing from a trackpad click? Or a way to distinguish whether I'm getting the call because of an actual two finger swipe?
2
0
188
Jan ’25
Failing UI Test for new floating Tabbar iOS 18+
Xcode 16.1 iOS 18.1 iPad Air 13-inch (M2) I have created a completely new Xcode project with Swift and Storyboard. In Storyboard, I only have a tabBarController with two attached UIViewControllers. The code from the base project hasn't been changed at all. I created a UITest with a very simple premise. let app = XCUIApplication() override func setupWithError() throws { continueAfterFailure = false app.launch() } func testTabBarExistence() { let tabBar = app.tabBars.element(boundBy: 0) XCTAssertTrue(tabBar.waitForExistence(timeout: 5), "Tab bar should exist") } But this test always fails for iPad on iOS 18+, but it will succeed for anything lower (e.g. 17.5)
1
1
305
Jan ’25
PKInk - no eraser stroke
I am trying to convert some of my older drawings to a PKCanvas. In my older drawings, I had an eraser stroke which erases anything that the stroke intersected with. I am able to convert all the strokes except an eraser stroke which doesn't seem to exist in PKCanvas. The user tool exists, but PKInkTypePen etc... doesn't contain an eraser type. Is there any way to create an "eraser type stroke" so I can convert my drawing strokes to use the PKCanvas? Thanks
1
0
167
Jan ’25
Can I edit NSTextLineFragment position or update manually in TextKit2
In my app, User can select word in the UITextView, then I want to insert a content under the selected words(the comment words shouldn't be selected).like: I found TextKit2 only support edit NSTextParagraph position, or I missed some features in NSTextLayoutManager? I try to override the NSTextLayoutFragment and update the draw(at point: CGPoint, in context: CGContext) but I found, user still can select the origin content at the origin position, even if the layer of linefragment layer on the corrent position not the origin position.
2
0
489
Jan ’25
iOS 18: “Settings” button on location permission alert does nothing, logs BUG IN CLIENT OF UIKIT warning
Hello everyone, I’m encountering a problem on the latest iOS 18 related to location permissions. When the user denies location access, my app triggers the standard system prompt asking them to enable location from Settings. On iOS 17 and below, tapping the “Settings” button in this system alert would successfully navigate the user to my app’s Settings page. However, on iOS 18, nothing happens. Instead, I see the following warning in the Xcode console: Warning : BUG IN CLIENT OF UIKIT: The caller of UIApplication.openURL(:) needs to migrate to the non-deprecated UIApplication.open(:options:completionHandler:). Force returning false (NO). Important details and context: In my own code, I have already replaced all calls to openURL(:) with open(:options:completionHandler:). I searched the entire codebase for usage of openURL: and didn’t find any. The alert that appears is the system location alert (iOS-generated), not a custom UIAlertController. Thus, I have no direct control over the underlying call. On iOS 17 (and below), tapping “Settings” in the same system dialog works perfectly and takes the user to the app’s permission page. The console message implies that somewhere—likely inside the system’s own flow—the deprecated API is being called and blocked on iOS 18. What I’ve tried: Verified I am not calling openURL: anywhere in my code. Confirmed that UIApplication.openSettingsURLString works when I programmatically open it in a custom alert. Tested multiple times on iOS 17 and iOS 18 to confirm the behavior difference. Steps to reproduce: Install the app on a device running iOS 18 Beta. Deny location permission when prompted. Trigger a piece of code that relies on location (e.g., loading a map screen) so that the OS automatically shows its standard “Location is disabled” alert, which includes a “Settings” button. Tap “Settings.” On iOS 17, this navigates to the app’s Settings. On iOS 18 Beta, it does nothing, and the console logs the BUG IN CLIENT OF UIKIT warning. Questions: Is this a known iOS 18 bug where the system’s own alert is still using the deprecated openURL: call? If so, are there any workarounds besides presenting a custom alert that manually calls open(_:options:completionHandler:)? Thank you in advance. Any guidance or confirmation would be appreciated!
1
1
432
Jan ’25
Scroll to bottom after reload row issue
Im creating a chat using uiTableView. The response is send as streaming so I need to reload last cell até every response update. However when I do reload row and scroll to bottom, the content of the last cell seems to be drag to the bottom instead of looking as a regular scroll.
3
0
201
Jan ’25
UIDocumentInteractionController - delegate methods will not be called
Hello, we are presenting a UIDocumentInteractionController within our app, so the user can share some documents. Sharing basically works but we are facing the problem that the two delegate methods documentInteractionController(UIDocumentInteractionController, willBeginSendingToApplication: String?) and documentInteractionController(UIDocumentInteractionController, didEndSendingToApplication: String?) are never being called. Other delegate methods such as documentInteractionControllerWillBeginPreview(UIDocumentInteractionController) are called just fine. Everything worked as expected when we last checked a year ago or so, but doesn't anymore now, even after updating to the latest iOS 18.3. Does anybody know of a solution for this? For reference, this is the simplified code we are using the reproduce the issue: import UIKit import OSLog class ViewController: UIViewController, UIDocumentInteractionControllerDelegate { let log = Logger(subsystem: "com.me.pdfshare", category: "app") var documentInteractionController: UIDocumentInteractionController! override func viewDidLoad() { super.viewDidLoad() guard let pdfURL = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return } documentInteractionController = UIDocumentInteractionController(url: pdfURL) documentInteractionController.delegate = self documentInteractionController.presentPreview(animated: true) } // MARK: - UIDocumentInteractionControllerDelegate func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController { log.notice("documentInteractionControllerViewControllerForPreview") return self } // This will be called. func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) { log.notice("willBeginSendingToApplication") } // This will NOT be called. func documentInteractionController(_ controller: UIDocumentInteractionController, didEndSendingToApplication application: String?) { log.notice("didEndSendingToApplication") } // This will NOT be called. }
2
0
180
Jan ’25
How to use UIButtonConfiguration to set attributedTitle based on control state?
I use for (NSNumber *controlState in AllControlStates()) { [uiButton setAttributedTitle:attributedStrings[controlState] forState:controlState.unsignedIntegerValue]; } to set different title colors based on different controlState now. How to use UIButtonConfiguration to set attributedTitle based on control state? I am deprecating contentEdgeInsets for my button now, I have to set all the other properties on configuration to maintain the current look of my button.
1
0
194
Jan ’25
UIDocumentBrowserViewController - adjust order and color of navigation bar items
I'm using UIDocumentBrowserViewController. This view controller automatically creates a TabView with navigation titles and up to two trailing navigation bar items. To visualize this, open the Files app by Apple on an iPhone. I want to do the following: Add a third button and place it farthest on the trailing side. Keep all three buttons blue (the default color), but adjust the color of the navigation title to use the primary text color (it is also currently blue, by default) Button Order If my button is represented by C, then the order from left-to-right or leading-to-trailing should be A B C. I tried to add it by using additionaltrailingnavigationbarbuttonitems: class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() let button = UIBarButtonItem(...) additionalTrailingNavigationBarButtonItems.append(button) } } This always adds it as the leftmost trailing item. The order when the view loads is C A B, where C represents my button. Here are some things I've tried: Add it in viewWillAppear - same results. Add it in viewDidAppear - same results. Add it using rightBarButtonItems - does not show up at all. insert it at: 0 instead of appending it - same results. Add it with a delay using DispatchQueue.main.async - same results. After some experimentation, I realized that the arrays referenced by additionalTrailingNavigationBarButtons and rightBarButtonItems seem to be empty, other than my own button. This is the case even if the DispatchQueue delay is so long that the view has already rendered and the two default buttons are clearly visible. So I'm not sure how to place my button relative to these, since I can't figure out where they actually are in the view controller's properties. How do I put my button farther to the trailing/right side of these two default buttons? Title Color The navigation titles created by UIDocumentBrowserViewController are blue when not in their inline format. I want them to use the primary text color instead. In viewDidLoad, I could do something like this: UINavigationBar.appearance().tintColor = UIColor.label This will change the title color to white or black, but it will also change the color of the buttons. I've tried various approaches like titleTextAttributes, and none of them seem to work with this view controller. How do I change just the color of the navigation title, and not the color of the navigation bar items?
0
0
203
Jan ’25
Opening recent files from Dock with MacCatalyst app
We are developing an MacOS app from our iOS app using MacCatalyst. If I press long on the app icon on the Dock, a list of recent files appears. If I tap one one of these files nothing happens. I would expect the scene delegate function: func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) would be called but it is not. Can somebody maybe explain what I am missing here? The list of recent files also appears in the Menu under File > Open recent files. There I can tap on a file and it it is opened correctly using the scene delegate method mentioned above. The files can also be opened with the app using the Finder, so the associated file types with the app are correct.
0
0
197
Jan ’25
TextField using numberPad shows incorrectly shows autofill for one time code
If I show a textfield in my app and set nothing else on it but the following, The keyboard will show an autofill suggestion from a password manager for a one time code. textField.keyboardType = .numberPad In this case, the text field is for typing in a count, so iOS suggesting to autofill a one time code is incorrect. Setting textField.textContentType to nil has no affect on the behaviour. Prerequisites to reproduce an app with an associated domain an entry in a password manager with a one time code for the domain a textfield with keyboardType set to numberPad
2
0
458
Jan ’25
How to share 'back facing' iOS camera app at same time Eye Tracking app needs 'front facing' camera?
While using my xmas present of a new iPhone and iOS 18.2, I figured I'd try the Eye Tracker app. I've been working with clients successfully using Tobii and other existing eye trackers. In my limited tests, Apple has room for improvement. My main issue is with the camera app which cannot be used at the same time while using the Eye Tracker app. I get an error popup from Apple: Camera is use by another app The image below is from my app showing the popup message "Camera in use by another app", but the same error occurs on the installed camera app. This error is from Apple, not my app. For terminology: 'front' camera is the one pointing at the user (the selfi camera) while 'back' camera is the main one with multiple lenses. Eye tracking needs the 'front' camera. It seems when an app uses the camera, it takes over both the front and back facing cameras (since you might swap them). Thus another app, especially Eye Tracking, cannot use just the front facing camera at the same time. That limits use of Eye Tracking, in particular one cannot take pictures or click any buttons on an app that uses the camera. Anyone know of a way for an app to not take over both front and back cameras at the same time? If I can separate them, the Eye Tracker could use the front camera while the camera uses the back camera.
1
0
248
Jan ’25
UIDocumentPickerViewController
I'm upgrading my app from minVersion iOS 11 to iOS 12. My compiler says that UIDocumentMenuViewController with UIDocumentPickerViewController is deprecated, they recommend to use directly the last one. So I change the code. fileprivate func openDocumentPicker() { let documentPicker = UIDocumentPickerViewController( documentTypes: [ "com.adobe.pdf", "org.openxmlformats.wordprocessingml.document", // DOCX "com.microsoft.word.doc" // DOC ], in: .import ) documentPicker.delegate = self view.window?.rootViewController?.present(documentPicker, animated: true, completion: nil) } When I open the picker in iOS 17.2 simulator and under it is well shown, like a page sheet. But in iOS 18.0 and up at first it opens like a page sheet with no content but then it is displayed as a transparent window with no content. Is there any issue with this component and iOS 18? If I open the picker through UIDocumentMenuViewControllerDelegate in an iphone with iOS 18.2 it is well shown. Image in iOS 18.2 with the snippet The same snippet in iOS 17.2 (and expected in older ones)
0
0
189
Jan ’25