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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

KeyboardLayoutGuide very unreliable on iOS17 RC
KeyboardLayoutGuide is unusable on iOS17 Release Candidate. Constantly reporting wrong values and missing updates. Sample app description NavigationController with two ViewControllers, the first one making use of KeyboardLayoutGuide to place a view on top of the keyboard, second ViewController with an InputField. Here the logic using keyboardLayoutGuide. class FirstViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let v = UILabel() v.textColor = .white v.textAlignment = .center v.text = "View always above Keyboard" v.backgroundColor = .blue v.translatesAutoresizingMaskIntoConstraints = false view.addSubview(v) NSLayoutConstraint.activate([ v.leadingAnchor.constraint(equalTo: view.leadingAnchor), v.trailingAnchor.constraint(equalTo: view.trailingAnchor), v.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor), ]) } } iPhone Scenario Push the second ViewController Focus the Input Field Pop the ViewController KeyboardLayoutGuide will report to the first ViewController as the keyboard is still visible, misplacing any view that makes use of it. iPad Scenario 1 Enable Stage Manager Run the Sample app and any other app side by side Focus on any input field on the second app KeyboardLayoutGuide will correctly update the view that makes use of it on the Sample App. Tap on the Sample app to acquire focus KeyboardLayoutGuide won't be updated, misplacing any views that makes use of it. iPad Scenario 2 Run the Sample app and any other app side by side Focus on any input field on the second app Rotate the device KeyboardLayoutGuide will misplace any view that makes use of it. Feedback was submitted FB12844057
4
3
611
Sep ’23
SKStoreProductViewController fails to present on iOS 17 RC
Hello, I experience a serious issue where calling presentViewController: animated: on SKStoreProductViewController is executed and completion is called, but the view controller isn't visible on screen. The system thinks that it's the presentedViewController, and my presentingViewController is frozen. Tapping the screen prints a weird Console log of dismissViewControllerAnimated on SKStoreProductViewController. The code is executed inside an SDK that is integrated in apps, and the issue occurs only in some of the apps. Any idea what could cause this issue? Thanks!
7
3
1.3k
Sep ’23
How to find freeze that doesn't happen to me?
A handful of my customers have reported a consistent freeze in my app (smells like either a thread deadlock or an infinite recursion to me). It's working properly for most people, but if 3 people are reporting it to me that says to me that probably 300 are experiencing it but staying quiet. It happens every time they take a certain kind of action. But it never happens to me so I can't figure out what is breaking. No crash is happening, so I'm not getting any reports via Firebase. It doesn't appear to be related to their data, because they can have someone else use a different device, login to their account, download all of their data, and then successfully do the thing that freezes 100% of the time on their original device. I've got one of these customers set up on TestFlight so I can send them test versions of the app with some debug collection code. I created my own version of a tracelog and write a line to a file whenever I start/end a function. I've added those tracelog calls to a bunch of methods and classes (but not all). The action that causes the freeze is when they tap Edit on a record. What's supposed to happen is that I modally present a nav controller containing an EditBlahViewController. The trace logs show that the EditBlahViewController gets through viewDidLoad, viewWillAppear, two rounds of viewWillLayoutSubviews/viewDidLayoutSubviews... but then never gets to viewDidAppear. I've tried updating more and more functions/classes with the tracelog calls, but I can't find any infinite recursions. I've added tracelogs to all calls involving dispatching to other threads (especially synchronous dispatches to the main thread) but I don't see any deadlocks. Every dispatch to main starts and ends properly and then goes on to the next thing. User is on iOS 16.6.1 with an iPhone 12. I don't know what else to try. How can I debug this at a distance and figure out where the problem is?
6
0
1.5k
Sep ’23
Xcode13.4.1&Xcode15 crash bug
let file = FileManager.groupPath.appendingPathComponent("test.pdf") UIGraphicsBeginPDFContextToFile(file.path, .zero, nil) UIGraphicsBeginPDFPageWithInfo(.init(x: 0, y: 0, width: 200, height: 200), nil) "😘".draw(in: .init(origin: .zero, size: .init(width: 10, height: 10)), withAttributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14)]) UIGraphicsEndPDFContext() When I use the above code to draw emoji or images with transparent channels, there will be a crash in draw function!
4
0
327
Sep ’23
UIImage not fitting in UIImageView frame
I have attached a UIImageView to my Navigation bar title view, however the image exceeds the frame no matter which values I input. Here is the code: override func viewDidLayoutSubviews() { // style the navbar let iconView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 30)) let image = UIImage(named: "fresh-appbar")! iconView.contentMode = .scaleAspectFit iconView.image = image navigationItem.titleView = iconView } I have also attached an image:
1
0
289
Sep ’23
NSInternalInconsistencyException
iOS16 above 0 CoreFoundation ___exceptionPreprocess + 164 1 libobjc.A.dylib _objc_exception_throw + 60 2 Foundation -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:] 3 UIKitCore ___UIKIT_DID_NOT_RECEIVE_A_REMOTE_CACONTEXT_FROM_COREANIMATION_INDICATING_A_POSSIBLE_BACKBOARDD_CRASH + 484 4 UIKitCore ___UIKIT_IS_REQUESTING_A_CACONTEXT_FROM_COREANIMATION + 64 5 UIKitCore +[_UIContextBinder createContextForBindable:withSubstrate:] + 400 6 UIKitCore -[_UIContextBinder _contextForBindable:] + 112 7 UIKitCore -[_UIContextBinder updateBindableOrderWithTest:force:] + 304 8 UIKitCore -[_UIContextBinder createContextsWithTest:creationAction:] + 80 9 UIKitCore -[UIWindowScene _prepareForResume] + 148 10 UIKitCore -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 756 11 UIKitCore -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 244 12 UIKitCore -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 336 13 FrontBoardServices -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 420 14 FrontBoardServices ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 15 FrontBoardServices -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168 16 FrontBoardServices ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 344 17 libdispatch.dylib __dispatch_client_callout + 20 18 libdispatch.dylib __dispatch_block_invoke_direct + 264 19 FrontBoardServices ___FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 NSInternalInconsistencyException Failed to create remote render context Lifecycle 09-16 12:49:47.944 UIApplication WillResignActive 09-16 12:49:48.484 UIApplication DidEnterBackground 09-16 12:53:38.998 UIApplication WillEnterForeground It seems, app becomes inactive before it 'willEnterForeground',then crash,I do not have any ideas of what happen.
1
0
478
Sep ’23
UIMenuController deprecated
Hi, I would like to ask about migration from UIMenuController since it has been deprecated, so I want a context menu work like UIMenuController for UIView, I've found UIEditMenuInteraction but it's only work for UITextView or UITextField and UIContextMenuInteraction which has different appearance with UIMenuController. So, I want migrate from UIMenuController without change the existing user interface. Thank You
2
0
787
Sep ’23
A new value for UIRequiredDeviceCapabilities, "iphone-performance-gaming-tier", is submitted to App Store Connect using Xcode 15.0 and iOS 17.0+, but the bundle is declared invalid.
According to UIRequiredDeviceCapabilities documentation https://developer.apple.com/documentation/bundleresources/information_property_list/uirequireddevicecapabilities/, the value iphone-performance-gaming-tier has been added. The description is quoted below. iphone-performance-gaming-tier Requires the graphics performance and gaming features equivalent to the iPhone 15 Pro and iPhone 15 Pro Max. Available in iOS 17.0 and later. Unavailable in visionOS. In Info.plist of Xcode 15.0 (15A240d), setting iphone-performance-gaming-tier is correctly displayed in human readable format. However, when archiving a build containing this value and submitting it to App Store Connect, I receive an email stating that the bundle is invalid. The iphone-performance-gaming-tier is not available at this time, although its documentation states that it is available in iOS 17.0 and later. How can I use this value? For example, do I need a special entitlement?
4
0
1.2k
Sep ’23
NSCollectionLayoutSection in UICollectionViewCompositionalLayout
I have faced an issue related to the NSCollectionLayoutSection in UICollectionViewCompositionalLayout. Here is my code to set a section in collection view. let item = NSCollectionLayoutItem.init(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1))) let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)), subitems: [item]) section = NSCollectionLayoutSection(group: group) section.contentInsets = .init(top: 15, leading: 0, bottom: 0, trailing: 0) The above code works correctly on iOS versions less than 17. But on iOS 17, the content insets of this section always equal 0. This is an empty section; may this be a root cause on iOS 17? It would be appreciated if you could help me on this issue.
0
1
217
Sep ’23
Opening AirDropped files in 3rd party apps in iOS 17
Since updating to iOS 17 there doesn't seem to be a way to automatically open files AirDropped into any applications. The files get downloaded to the Files application and you can open them from there, but previously you could open them straight in another application. There doesn't seem to be any documentation to this change. Is there still a way to open AirDropped files directly in a non-Apple published application?
16
9
5.3k
Sep ’23
UIImageView preferredImageDynamicRange not working
I am trying to display HDR Images (ProRAW) within UIImageView using preferredImageDynamicRange. This was shown in a 2023 WWDC Video let imageView = UIImageView() if #available(iOS 17.0, *) { self.imageView.preferredImageDynamicRange = UIImage.DynamicRange.high } self.imageView.clipsToBounds = true self.imageView.isMultipleTouchEnabled = true self.imageView.contentMode = .scaleAspectFit self.photoScrollView.addSubview(self.imageView) I pull the image from PHImageManager: let options = PHImageRequestOptions() options.deliveryMode = .highQualityFormat options.isNetworkAccessAllowed = true PHImageManager.default().requestImage(for: asset, targetSize: self.targetSize(), contentMode: .aspectFit, options: options, resultHandler: { image, info in guard let image = image else { return } DispatchQueue.main.async { self.imageView.image =image if #available(iOS 17.0, *) { self.imageView.preferredImageDynamicRange = UIImage.DynamicRange.high } } } Issue The image shows successfully, yet not in HDR mode (no bright specular highlights, as seen when the same image ((ProRAW) is pulled on the native camera app. What am I missing here?
1
0
706
Sep ’23
Swift PKLassoTool custom menu
I’m building a drawing app and I want to add more things I can do with the strokes selected by the PKLassoTool. Is there a way to edit the menu of buttons that appears when you make a selection with the lasso tool? And then is there away to pass the selected strokes into a function? I’ve looked at the Apple documentation but there doesn’t seem to be a lot of support to doing anything with the lasso tool.
2
2
507
Sep ’23
-[UINSUIKitBackgroundingController _updateAppWideBackgroundStateSlammingNotifyingDelegate:]: Called off the main thread. CoreFoundation __exceptionPreprocess
iPad Pro 12.9 、iOS15.4 (21E230) #700003 NSInternalInconsistencyException -[UINSUIKitBackgroundingController _updateAppWideBackgroundStateSlammingNotifyingDelegate:]: Called off the main thread. CoreFoundation __exceptionPreprocess CoreFoundation __exceptionPreprocess + 220 2 Foundation -[NSCalendarDate initWithCoder:] + 0 3 UIKitMacHelper -[UINSUIKitBackgroundingController _updateAppWideBackgroundStateSlammingNotifyingDelegate:] + 504 4 UIKitMacHelper -[UINSUIKitBackgroundingController transitionUIAppThroughBackgroundStateIfNecessary] + 144 5 UIKitMacHelper -[UINSApplicationLifecycleController transitionAppThroughBackgroundState] + 308 6 UIKitMacHelper -[UINSApplicationDelegate _toggleAppForegroundStateIfAppStoreURL:] + 276 7 UIKitMacHelper __54-[UINSApplicationDelegate openURL:options:completion:]_block_invoke_2 + 196 8 AppKit _NSWorkspaceHandleLSOpenResult + 164 9 LaunchServices _LSFireCompletionHandler(void (__LSASN const*, unsigned char, __CFError*) block_pointer, NSURL*, NSURL*, NSDictionary<NSString*, objc_object*>, objc_object, bool, NSError*) + 200 10 LaunchServices _LSOpenAsyncCommonDispatched(objc_object*, NSArray<NSURL*>, NSURL, objc_object*, NSDictionary<NSString*, objc_object*>, NSObject<OS_dispatch_semaphore>, void (__LSASN const*, unsigned char, __CFError*) block_pointer) + 5732 11 libdispatch.dylib _dispatch_call_block_and_release + 32 17 libsystem_pthread.dylib start_wqthread + 8 #0 Thread 0 libsystem_kernel.dylib mach_msg_trap + 8 4 CoreFoundation CFRunLoopRunSpecific + 600 5 HIToolbox RunCurrentEventLoopInMode + 292 6 HIToolbox ReceiveNextEventCommon + 564 7 HIToolbox _BlockUntilNextEventMatchingListInModeWithFilter + 72 8 AppKit _DPSNextEvent + 860 9 AppKit -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1328 10 AppKit -[NSApplication run] + 596 11 AppKit NSApplicationMain + 1132 12 AppKit +[NSWindow _savedFrameFromString:] + 0 13 UIKitMacHelper UINSApplicationMain + 1276
1
0
491
Sep ’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
2
4
820
Sep ’23
DatePicker Accessibility
Hello, sorry if this is a repost, but I couldn't find an answer anywhere. I'm french, thus date are displayed dd//mm//yy for us. on the DatePicker, when the mode .wheels is enabled, i can see the d/m/y. Now, let's say there are 30 days on the current month and we are currently the 27th of september The voiceOver will announce "27... 12 elements on the list" Switching to the month will announce "9... 30 elements on the list" The correct result should be "27... 30 elements on the list" and "9... 12 elements on the list" I don't know if it is related but for some reason, even if my phone is set to language french, region France, the Local.current return en_FR ( and my app support french english language so I was expecting fr_FR) So I tried to set the local and the accessibility language of the picker to french but the result is the same. Another problem occur with the date picker set on .inline Months are displayed in french, voiceOver announce it in french but as soon as I switch to the days it will announce the number in english. I'tried on a new project with nothing else but the picker and I still have the same results Are those some bugs or am I missing something ?
3
0
597
Sep ’23
UIKit in visionOS
The default framework of visionOS is SwiftUI, but it can also be combined with UIKit in SwiftUI, and Apple has also released video documents and other content for this purpose. But what I want to know is that SwiftUI is much simpler than UIKit, but why does Apple recommend developers to combine with UIKit in SwiftUI? I also want to know what are the advantages of SwiftUI and UIKit in visionOS? I hope you can reply to my two questions. Thank you!
1
0
503
Sep ’23
New AirDrop experience in iOS 17 not working with "activityItemsConfiguration" in UIKit
Hi, I noticed that setting an array with a URL in it to the "activityItemsConfiguration" property of a UIViewController does not seem to trigger this UX. I've tried: Without app installed With app installed Without contact in destination device (NameDrop interference, etc.) With contact in destination device Every time, it always just shows NameDrop after the animation, which is annoying because it's not the expected UX. And yet, if you say "Hey Siri, share this" it works albeit with more steps. How is this supposed to work? 🤔 Tested on devices all running iOS 17.0.2! Also filed FB31823717.
1
0
604
Sep ’23