Hi everyone! I'm thrilled to share that I'm conducting a field research as part of my final university project, focused on iOS architecture.
The goal is to dive deeper into the best practices, challenges, and trends in the iOS development world. To make this research truly impactful, I need your help!
If you're an iOS developer, I’d love it if you could take a few minutes to answer a short survey. Your insights and experiences will be invaluable for my research, and I greatly appreciate your
support!
Here is the link:
https://docs.google.com/forms/d/e/1FAIpQLSdf9cacfA7my1hnlazyl7uJraa2oTsQ7dJBWvFtZ_4vbYenRA/viewform?usp=send_form
Thank you so much in advance for helping me out—feel free to share this post with others who might also be interested. Let’s build something amazing together! 💡✨
UIKit
RSS for tagConstruct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.
Posts under UIKit tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi guys, I’m making a simple note taking app and I want to support markdown functionality. I have tried to find libraries and many other GitHub repos but some of them are slow and some of them are very hard to implement and not very customizable.
In WWDC 22 apple also made a markdown to html document app and I also looked at that code and it was awesome. It was fast and reliable (Apple btw).
But the only problem I am facing is that the markdown text is on the left side and the output format is on the right in the form of html. I don’t want that I want both in the same line. In bear notes and things 3 you can write in markdown and you can see that it is converting in the same line. I have also attached example videos. So, I have markdown parser by apple but the only thing in the way is that it is converting it into a html document. Please help me with this. Also please look into the things 3 video they have also completely customized the text attributes selection menu. By default with UITextView we can only enable text attributes and it shows like this.
By clicking more we get the complete formatting menu but not the slider menu which is more convenient. Please also help me this. I don’t know if I can provide apple file but it is from wwdc 22 supporting desktop class interaction
Some time ago I read somewhere that one can get a file icon on iOS like this:
UIDocumentInteractionController(url: url).icons.last!)
but this always returns the following image for every file:
Today I tried the following, which always returns nil:
(try? url.resourceValues(forKeys: [.effectiveIconKey]))?.allValues[.effectiveIconKey] as? UIImage
Is there any way to get a file icon on iOS?
You can try the above methods in this sample app:
struct ContentView: View {
@State private var isPresentingFilePicker = false
@State private var url: URL?
var body: some View {
VStack {
Button("Open") {
isPresentingFilePicker = true
}
if let url = url {
Image(uiImage: UIDocumentInteractionController(url: url).icons.last!)
if let image = (try? url.resourceValues(forKeys: [.effectiveIconKey]))?.allValues[.effectiveIconKey] as? UIImage {
Image(uiImage: image)
} else {
Text("none")
}
}
}
.padding()
.fileImporter(isPresented: $isPresentingFilePicker, allowedContentTypes: [.data]) { result in
do {
let url = try result.get()
if url.startAccessingSecurityScopedResource() {
self.url = url
}
} catch {
preconditionFailure(error.localizedDescription)
}
}
}
}
I have an alertController that is presented as popover on iPad
let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: alertStyle)
if let ppc = alertController.popoverPresentationController {
// …
}
Is it possible to change the message font color (which is really very light on iPad) ?
It is OK on iPhone with the same alert (not popover): text is much more readable:
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.)
After the app is put in background for sometime and the app crashes,
Some cases have the webView involvement before putting the app in to background for quite sometime and pulled into foreground.
Here's the crash log information.
Identifier: com.app.myapp
Version: 2.3.3 (30)
AppStoreTools: 16C5031b
AppVariant: 1:iPhone9,1:15
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.app.myapp [2833]
Date/Time: 2024-12-12 17:30:57.4489 +0100
Launch Time: 2024-12-12 17:04:19.7290 +0100
OS Version: iPhone OS 15.5 (19F77)
Release Type: User
Baseband Version: 9.61.00
Report Version: 104
**Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000018f1358e0
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [82527]
Triggered by Thread: 10
Kernel Triage:
VM - Fault hit memory shortage**
Thread 10 Crashed:
0 WebKit 0x000000018f1358e0 WTFCrashWithInfo(int, char const*, char const*, int) + 20 (Assertions.h:732)
1 WebKit 0x000000018f72e348 WebKit::allDataStores() + 72 (WebsiteDataStore.cpp:100)
2 WebKit 0x000000018f72e278 WebKit::WebsiteDataStore::forEachWebsiteDataStore(WTF::Function<void (WebKit::WebsiteDataStore&)>&&) + 24 (WebsiteDataStore.cpp:107)
3 WebKit 0x000000018f67c440 WebKit::WebProcessPool::updateProcessAssertions() + 52 (WebProcessPool.cpp:1773)
4 WebKit 0x000000018f684508 WebKit::WebProcessProxy::didSetAssertionType(WebKit::ProcessAssertionType) + 880 (Function.h:82)
5 WebKit 0x000000018f5bfdd0 WebKit::ProcessThrottler::setAssertionType(WebKit::ProcessAssertionType) + 712 (ProcessThrottler.cpp:148)
6 WebKit 0x000000018f5bf9b4 WebKit::ProcessThrottler::updateAssertionIfNeeded() + 408 (ProcessThrottler.cpp:176)
7 WebKit 0x000000018f5c42b0 WebKit::ProcessThrottler::Activity<(WebKit::ProcessThrottler::ActivityType)1>::Activity(WebKit::ProcessThrottler&, WTF::ASCIILiteral) + 76 (ProcessThrottler.cpp:58)
8 WebKit 0x000000018f659958 WebKit::WebPageProxy::runJavaScriptInFrameInScriptWorld(WebCore::RunJavaScriptParameters&&, std::__1::optional<WTF::ObjectIdentifierWebCore::FrameIdentifierType >, API::ContentWorld&, WTF::Comple... + 240 (ProcessThrottler.h:66)
9 WebKit 0x000000018f3ca7cc -[WKWebView _evaluateJavaScript:asAsyncFunction:withSourceURL:withArguments:forceUserGesture:inFrame:inWorld:completionHandler:] + 1352 (WKWebView.mm:1151)
10 WebKit 0x000000018f131700 -[WKWebView evaluateJavaScript:completionHandler:] + 120 (WKWebView.mm:896)
11 MyApp 0x00000001044e7e64 cli_signalHandler + 2420
12 MyApp 0x00000001044e4470 getExtraInfoId + 132792
13 MyApp 0x00000001044c2b18 CLI_Reset + 50684
14 MyApp 0x00000001044c2a18 CLI_Reset + 50428
15 MyApp 0x00000001044c1cec CLI_Reset + 47056
16 MyApp 0x00000001044c27e8 CLI_Reset + 49868
17 MyApp 0x00000001044e01f4 getExtraInfoId + 115772
18 MyApp 0x0000000104492498 StringToScreenDensityLevel + 4588
19 libdispatch.dylib 0x0000000180e80094 _dispatch_client_callout + 16 (object.m:560)
20 libdispatch.dylib 0x0000000180e22bb8 _dispatch_continuation_pop$VARIANT$mp + 440 (inline_internal.h:2622)
21 libdispatch.dylib 0x0000000180e348dc _dispatch_source_invoke$VARIANT$mp + 1668 (source.c:596)
22 libdispatch.dylib 0x0000000180e22730 _dispatch_queue_override_invoke + 424 (queue.c:0)
23 libdispatch.dylib 0x0000000180e2fb94 _dispatch_root_queue_drain + 340 (inline_internal.h:0)
24 libdispatch.dylib 0x0000000180e3039c _dispatch_worker_thread2 + 172 (queue.c:6935)
25 libsystem_pthread.dylib 0x00000001dc483dd4 _pthread_wqthread + 224 (pthread.c:2612)
26 libsystem_pthread.dylib 0x00000001dc48393c start_wqthread + 8 (:-1)
Thread 10 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000064 x1: 0x000000018fad60a0 x2: 0x000000018fad6189 x3: 0x0000000000000113
x4: 0x0000000000000030 x5: 0x0000000100000030 x6: 0x0000000000000000 x7: 0x0000000000000001
x8: 0x000000016fd6b000 x9: 0x0000000106dd4580 x10: 0x000000000000002c x11: 0x0000000000020408
x12: 0x0000000000080000 x13: 0x0000000000000000 x14: 0x0000020000011000 x15: 0x0000000100000000
x16: 0x00000001dc48425c x17: 0x0000000000000000 x18: 0x0000000000000000 x19: 0x000000016fd6a418
x20: 0x0000000282ece080 x21: 0x00000002834ac2a0 x22: 0x00000001f694c000 x23: 0x0000000117004a80
x24: 0x0000000283bb6558 x25: 0x000000011a00a1d8 x26: 0x0000000000000000 x27: 0x0000000000000002
x28: 0x000000016fd6b180 fp: 0x000000016fd6a3d0 lr: 0x000000018f72e348
sp: 0x000000016fd6a3b0 pc: 0x000000018f1358e0 cpsr: 0x60000000
esr: 0xf200c471 (Breakpoint) pointer authentication trap IB
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?
application(_:open:sourceApplication:annotation:) method is already Deprecated, so when I use Smart App Banners, how to Provide Navigational Context to my App?
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
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
I have a complex app that requires the main SwiftUI view of the app to be embedded inside an NSHostingView which is a subview of an NSViewController's view. Then this NSViewController is wrapped using NSViewControllerRepresentable to be presented using SwiftUI's Window. And if I have a TimelineView inside my SwiftUI view hierarchy, it causes constant recalculation of the layout.
Here's a simplified demo code:
@main
struct DogApp: App {
private let dogViewController = DogViewController()
var body: some Scene {
Window("Dog", id: "main") {
DogViewControllerUI()
}
}
}
private struct DogViewControllerUI: NSViewControllerRepresentable {
let dogViewController = DogViewController ()
func makeNSViewController(context: Context) -> NSViewController { dogViewController }
func updateNSViewController(_ nsViewController: NSViewController, context: Context) {}
func sizeThatFits(_ proposal: ProposedViewSize, nsViewController: NSViewController, context: Context) -> CGSize? {
debugPrint("sizeThatFits", proposal)
return nil
}
}
public class DogViewController: NSViewController {
public override func viewDidLoad() {
super.viewDidLoad()
let mainView = MainView()
let hostingView = NSHostingView(rootView: mainView)
view.addSubview(hostingView)
hostingView.translatesAutoresizingMaskIntoConstraints = false
hostingView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
hostingView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
hostingView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
hostingView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}
struct MainView: View {
var body: some View {
VStack {
TimelineView(.animation) { _ in
Color.random
.frame(width: 100, height: 100)
}
}
}
}
extension Color {
static var random: Color {
Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
When running it's printing out this repeatedly (multiple times a second).
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(559.0), height: Optional(528.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(0.0), height: Optional(0.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(559.0), height: Optional(528.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(0.0), height: Optional(0.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(559.0), height: Optional(528.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(0.0), height: Optional(0.0))
"sizeThatFits" SwiftUI.ProposedViewSize(width: Optional(559.0), height: Optional(528.0))
If I run an equivalent code for an iPad, it only prints twice. If I comment out TimelineView on macOS, then it only prints out the above logs when resizing the app window.
The main reason this is an issue is that it's clearly causing dramatic degradation in performance. I was told to submit a bug report after I submitted TSI so a SwiftUI engineer could investigate it. Case-ID: 7461887. FB13810482. This was back in May but I received no response. LLMs are no help, and I've experimented with all sorts of workarounds. My last hope is this forum, maybe someone has an idea of what might be going on and why the recalculation is happening constantly on macOS.
Hi.
I know to know which window gets hardware keyboard events (such as shortcut key) currently on iPad.
Until iPadOS 15.0, UIApplication.shared.keyWindow, which was deprecated on iPadOS 13.0 and didBecomeKeyNotification/didResignKeyNotification.
But after iPadOS 15.0, a keyWindow is managed by UIScene, not by UIApplication.
Each scene of my app always has just one window.
For my purpose, checking deprecated UIApplication.shared.keyWindow is still effective but didBecomeKeyNotification and didResignKeyNotification don't work because they are fired when a change happens only inside the scene.
So my questions are,
What is the new alternative of UIApplication.shared.keyWindow?
I know a wrong hack like
UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.first?.windows.filter { $0.isKeyWindow }.first
does not work since the order of connectedScenes is not related with getting hardware keyboard events.
What are the new alternatives of didBecomeKeyNotification/didResignKeyNotification which work on inter-scene?
The second question is more crucial.
Because about the first question, I can still use deprecated UIApplication.shared.keyWindow.
Thanks.
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?
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.
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!
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.
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.
}
For many years, I've noticed that although in native code I can handle continuous and simultaneous Apple pencil and touch inputs using UIKit, Safari and WKWebView's PointerEvents only seem to allow you to use one input type at a time. i.e. Apple Pencil down blocks touch input until lifted and touch input blocks Apple Pencil input. It's as though requiresexclusivetouchtype has been set in the underlying webkit implementation. There's decades of research (e.g. https://dl.acm.org/doi/10.1145/1866029.1866036 ) and several existing native applications in production showing that multimodal inputs open-up many unique and useful applications and interactions. Even a simple "hold object with finger" + "draw with stylus" controls are the norm. I recently built a native application using multimodal simultaneous inputs, but this is impossible to port to web due to the unexpected behavior of PointerEvents (and touch events, and mouse events; any variant exhibits the same behavior). I've researched and attempted to apply every possible flag, change, and css code to get this working, but I think the behind-the-scenes implementation is what's blocking the simultaneous touch types.
This is unexpected and undesired behavior because it's inconsistent with the native behavior. If it's unintended, it's a big priority to fix for creating better user experiences on the iPad. If it's intended, I do not believe that's reasonable (even if it might be more complex and used for more advanced applications). Please expose a way to support simultaneous touch types in iPadOS/iOS in both Safari and WKWebView.
At minimum, may we have a discussion on how to support the desired behavior? The simplest solution I can think of is to provide a webkit-platform-specific boolean in Safari and WKWebView called requiresExclusiveTouchType, which is set to False by default to keep the current behavior, and settable to True to get the more flexible behavior I'm expecting.
In macOS, I am encountering an issue where the system API fails to grant permission to open a file despite enabling the necessary Read/Write permissions within the SandBox. Could you please elucidate the reasons behind this behavior? Thanks!
func finderOpenFileSystem(at path: String) {
let fileURL = URL(fileURLWithPath: path)
guard FileManager.default.fileExists(atPath: path) else {
print("Error: File does not exist at path: \(path)")
return
}
let success = NSWorkspace.shared.open(fileURL)
if success {
print("File opened successfully: \(fileURL)")
} else {
print("Error: Failed to open file: \(fileURL)")
}
}
In the fileImporter on iOS, when I select a folder, the result is always a subfile belonging to the private folder. This prevents me from accessing these files within the app. However, I do not wish to store them in the sandbox environment. What steps can I take to resolve this issue?