Construct 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

Captured photos in wrong orientation
I'm building a custom camera screen that displays the camera image on a preview layer and then captures an image, using AVCaptureSession. When the picture is captured, I immediately load it into a UIImageView in order to display it to the user for approval. I've actually done this many times before, but this is the first time I've tried to do it in an app that supports interface rotation. If I hold the phone in Portrait mode and capture a picture, everything works as expected. When the user rotates the phone into Landscape orientation, I detect this and I replace the preview layer (AVCaptureVideoPreviewLayer) with a new one, specifying connection.videoRotationAngle in order to make the image appear in the right orientation. I'm a little surprised that this is necessary, and it's not a smooth transition, but that doesn't matter. What does matter is that when I capture the image, it is in the wrong orientation. I tried rotating it myself, but this doesn't seem to make any difference. What am I doing wrong?
0
0
62
5h
NSInternalInconsistencyException Failed to create remote render context
Some crashes were found, not many, but we could not locate the specific code because the error stack is a systematic method. Error: NSInternalInconsistencyException Failed to create remote render context Stack: 0 CoreFoundation 0x000000018a879d78 ___exceptionPreprocess + 220 1 libobjc.A.dylib 0x00000001a34de734 _objc_exception_throw + 60 2 Foundation 0x000000018c0ff358 -[NSMutableDictionary(NSMutableDictionary) initWithContentsOfFile:] + 0 3 UIKitCore 0x000000018d475f8c ___UIKIT_DID_NOT_RECEIVE_A_REMOTE_CACONTEXT_FROM_COREANIMATION_INDICATING_A_POSSIBLE_BACKBOARDD_CRASH + 572 4 UIKitCore 0x000000018d232484 ___UIKIT_IS_REQUESTING_A_CACONTEXT_FROM_COREANIMATION + 80 5 UIKitCore 0x000000018d1fc32c +[_UIContextBinder createContextForBindable:withSubstrate:] + 708 6 UIKitCore 0x000000018d13bdec -[_UIContextBinder _contextForBindable:] + 148 7 UIKitCore 0x000000018cf5bd20 -[_UIContextBinder updateBindableOrderWithTest:force:] + 480 8 UIKitCore 0x000000018d2e1200 -[_UIContextBinder createContextsWithTest:creationAction:] + 92 9 UIKitCore 0x000000018ccd64c0 -[UIWindowScene _prepareForResume] + 156 10 UIKitCore 0x000000018ce2ef80 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 876 11 UIKitCore 0x000000018ce72528 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 288 12 UIKitCore 0x000000018cdfc8c8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 476 13 FrontBoardServices 0x000000019c9dbe18 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 528 14 FrontBoardServices 0x000000019c9f413c ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 152 15 FrontBoardServices 0x000000019c9d9308 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 16 FrontBoardServices 0x000000019c9df824 ___94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 396 17 libdispatch.dylib 0x000000018a4e0a2c __dispatch_client_callout + 20 18 libdispatch.dylib 0x000000018a4e44e0 __dispatch_block_invoke_direct + 264 19 FrontBoardServices 0x000000019c9dac70 ___FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48 20 FrontBoardServices 0x000000019c9da040 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220 21 FrontBoardServices 0x000000019c9de700 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 22 CoreFoundation 0x000000018a89bf04 ___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 23 CoreFoundation 0x000000018a8acc90 ___CFRunLoopDoSource0 + 208 24 CoreFoundation 0x000000018a7e6184 ___CFRunLoopDoSources0 + 268 25 CoreFoundation 0x000000018a7ebb4c ___CFRunLoopRun + 828 26 CoreFoundation 0x000000018a7ff6b8 _CFRunLoopRunSpecific + 600 27 GraphicsServices 0x00000001a6899374 _GSEventRunModal + 164 28 UIKitCore 0x000000018d164e88 -[UIApplication _run] + 1100 29 UIKitCore 0x000000018cee65ec _UIApplicationMain + 364 30 ??? 0x00000001059b9ce4 0x00000001059b9ce4 + 0 These crashes occurred when the App was about to enter the foreground. (UIApplicationWillEnterForegroundNotification) These crashes occurred on systems from 15 to 18. crash.log
1
0
50
21h
Unable to inspect SwiftUI view embedded inside UITableView
We have been trying to migrate screens that were developed using UITool Kit to SwiftUI. In the process we have some screens that have SwiftUI embedded inside the UITool kit view. Our developers have defined accessibility ids for all elements in these views and these are inspectable using the native iOS xcode inspector. However when i try inspecting it with the appium inspector i get an empty list with no elements in the hierarchy tree. Attaching a screenshot of the element when inspecting through the native xcode accessibility inspector, Attaching a screenshot of the same screen when inspected through the appium inspector, Also tried printing the XCTest UI dump using appium method, `driver().executeScript("mobile:source", Map.ofEntries(Map.entry("format","description"))) The UI tree i get is the same that i get when inspecting through the appium inspector. Requesting support from the Apple team based on this ticket, [https://github.com/appium/appium/issues/20759)
0
0
61
1d
What's the best way to support Genmoji with SwiftUI?
I want to support Genmoji input in my SwiftUI TextField or TextEditor, but looking around, it seems there's no SwiftUI only way to do it? If none, it's kind of disappointing that they're saying SwiftUI is the path forward, but not updating it with support for new technologies. Going back, does this mean we can only support Genmoji through UITextField and UIViewRepresentable? or there more direct options? Btw, I'm also using SwiftData for storage.
0
0
94
2d
Limiting UITableView Width Across Different Table View Configurations
I have an iOS App which looks great on iPhone, portrait only, which makes a lot of use of UITableViews. On iPad those tables look stretched out in Landscape. On MacOS with Apple Silicon the app can be resized to any size and the table views look very stretched. There are views in the App which users want to resize so limiting app size not an option. I've been modifying the app's table views to limit their width and centre them using constraints. This isn't easy, it's a lot of work as UITableViewController doesn't allow for constraining the table width. Or does it? So I've changed them to UIViewControllers with UITableView imbedded in the root UIView with constraints. Looks really nice. Now I've just run into the limitation that static tables, which I have a number of, aren't allowed to be embedded. So how can I limit the width of them? I really don't want to add a lot of dynamic code. Please tell me there's an simpler, more elegant method to what really makes a much more aesthetically pleasing UI on iOS App running on iPad and MacOS? TIA!
2
0
84
2d
Replace MWPhotoBrowser with modern alternative
I have an iPad app, written in objective-c and distributed through Enterprise developer, as it is not for public use but specific to some large companies. The app has a local database and works offline For some functions of the app I need to display images (not edit or cut them, just display them) Right now there is integrated MWPhotoBrowser viewer, which has not been maintained for almost 10 years, so in addition to warnings in compilation I have to fight with some historical bugs especially on high resolution images. https://github.com/mwaterfall/MWPhotoBrowser Do you know of a modern and maintained OFFLINE photo viewer? I evaluate both free and paid (maybe an SDK). My needs are very basic I have found this one https://github.com/TimOliver/TOCropViewController, but I need to disable the photos edit features and especially I would lose the useful feature of displaying multiple images (mwphoto for multiple images showed a gallery)
0
0
111
1w
How to draw emojis like the Lock Screen customisation?
On iOS you can create a new Lock Screen that contains a bunch of emoji, and they'll get put on the screen in a repeating pattern, like this: When you have two or more emoji they're placed in alternating patterns, like this: How do I write something like that? I need to handle up to three emoji, and I need the canvas as large as the device's screen, and it needs to be saved as an image. Thanks! (I've already written an emojiToImage() extension on String, but it just plonks one massive emoji in the middle of an image, so I'm doing something wrong there.)
0
0
114
1w
iOS 18.1 crash UIHostingView.layoutSubviews() / swift_unknownObjectWeakAssign / objc_storeWeak
We're seeing sporadic crashes on devices running iOS 18.1 - both beta and release builds (22B83). The stack trace is always identical, a snippet of it below. As you can tell from the trace, it's happening in places we embed SwiftUI into UIKit via UIHostingController. Anyone else seeing this? 4 libobjc.A.dylib 0xbe2c _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 30 5 libobjc.A.dylib 0xb040 weak_register_no_lock + 396 6 libobjc.A.dylib 0xac50 objc_storeWeak + 472 7 libswiftCore.dylib 0x43ac34 swift_unknownObjectWeakAssign + 24 8 SwiftUI 0xeb74c8 _UIHostingView.base.getter + 160 9 SwiftUI 0x92124 _UIHostingView.layoutSubviews() + 112 10 SwiftUI 0x47860 @objc _UIHostingView.layoutSubviews() + 36
3
0
151
1w
Battery state notifications, when app is in the background
Does anyone know how battery state notification (UIDevice.batteryStateDidChangeNotification) is supposed to work regarding app foreground/background state? Assume there is no other reason why the app is running in the background. I have enabled UIDevice.current.isBatteryMonitoringEnabled when the app was in the foreground. What should happen if the external power is later connected or removed when the app is in the background? The docs don't mention this. Possibilities include I don't get a notification, so I should check the state myself when the app next comes to the foreground. I'll get a notification when the app next comes to the foreground, if the state changed while it was in the background. The app will be woken up in the background to receive the notification. The app will be kept running in the background while isBatteryMonitoringEnabled is true. It looks as if it's doing either 3 or 4, which I find a bit surprising. But is this influenced by the fact that it's connected (wirelessly) to the debugger?
4
0
133
1w
iOS18: UITabBarController.selectedViewController with UINavigationController
In a UITabBarController, its controllers are set to be UINavigationControllers. When programmatically setting the selectedViewController to a desired controller which is not currently displayed, the selected icon is correct however the actual view controller is still the previously selected. Pseudo code: tabController.controllers = [viewcontroller1, viewcontroller2, viewcontroller3].map{ UINavigationController(rootViewController: $0) } .... // let's say at some point tab bar is set to e.g. showing index 1 tabController.selectedController = tabController.controllers[0] // after this the icon of the 1st tab is correctly displayed, but the controller is still the one at index 1 I have noticed that if the controllers are simple UIViewController (not UINavigationController) upon setting the selectedViewController the TabController sets both icon and content correctly. But this is not the wanted setup and different UINavigationControllers are needed. Is this a new bug in iOS18? Any idea how to fix this (mis)behaviour?
1
0
214
1w
Updating Widget from App Intent called by Live Activity is inconsistent
(Also have a case ID, 9879068) We have an app that user use to check in/out from work for example. We have a button in-app do do this. Now I'm trying to add buttons to our widgets and our new live activity so that users don't have to open the app. It's crucial that the live activity and widgets always show the exact same state. Otherwise it'll look pretty bad if a user has both a live activity and a widget showin at the same time. However, we have noticed that sometimes, pressing the button in the live activity, running the app intent, will not always make the widget update (we call reloadAllTimelines()). The other way around, i.e. press the button on widget to update live activity always works. (they both call the same app intent) When running it in debug mode on a phone from Xcode, it always works, but when running it just on the phone it's unreliable. My first thought was, of course, that's related to the widget "budget", but according to the docs HERE, it should not be applied when interacting with a widget, calling an app intent. My question: HOW can I make my widget reliably refresh using an app intent invoked from a live activity?? I have a ready small project with simple buttons and trace labels that display this issue that I'm happy to supply to someone.
5
0
190
2d
Landscape safe area is incorrect when presenting SKStoreProductViewController
Hi. If the app is in landscape only and when the SKStoreProductViewController is presented, the safeArea changes to what looks like a portrait mode safe area. When the SKStoreProductViewController is dismissed, the safeArea does NOT revert back to the original values. Is there a way to force the safeArea to "reset"? I've submitted some bug tickets through Apple Feedback but I haven't received any response about it. The below code will pop up the SKStoreProductViewController and if you have a UIView that is constrained to the safe area, then you can visibly notice that the safe area is changed and doesn't go back. I have tested this on iPhone 14 Pro, iPhone 15, and iPhone 16 Pro and in the Simulators. The incorrect behavior happens on those and probably more. Thanks. #import "ViewController.h" #import <StoreKit/StoreKit.h> @interface ViewController () @property (nonatomic, strong) SKStoreProductViewController *productViewController; @end @implementation ViewController - (IBAction)buttonTapped:(id)sender { self.productViewController = [[SKStoreProductViewController alloc] init]; NSDictionary *parameters = @{ @"id" : @"6443575749" }; [self.productViewController loadProductWithParameters:parameters completionBlock:^(BOOL result, NSError * _Nullable error) { [self presentViewController:self.productViewController animated:YES completion:^{ // presented // The panel that is constraint to the safe area visibly shows that the safe area is no longer correct. }]; }]; } @end
0
1
182
1w
Storing SwiftUI Views to operate on it
I am creating a UIKit application but that contains SwiftUI Views embedded using the hostingcontroller. I have a particular approach for it..but it requires instantiating a swiftUI view, creating a hostingcontroller object from it and storing a reference to it. So that later If I wanted to update the view, I can simply get the reference back and update the swiftUI view using it. I wanted to understand what does apple recommends on this. Can we store a swiftUI instance? Does it cause any issue or it is okay to do so?
0
0
130
2w
UIPrintInteractionController IOS 18 issue on shared.
Only IOS 18+ bug. After tap share on UIPrintInteractionController - crash. So: #0 0x00000001bc38edf4 in _realizeSettingsExtension.cold.5 () #1 0x00000001bc310ed0 in _realizeSettingsExtension () #2 0x00000001bc33d100 in _ingestPropertiesFromSettingsSubclass () #3 0x00000001bc33be50 in __FBSIngestSubclassProperties_block_invoke () #4 0x00000001bc33bd7c in FBSIngestSubclassProperties () #5 0x00000001bc33d814 in FBSSettingForLegacySelector () #6 0x00000001bc30ecf8 in FBSSettingForSelector () #7 0x00000001bc350d98 in -[FBSMutableSceneSettings addPropagatedProperty:] () #8 0x00000001a64bae88 in __58-[_UISceneHostingController createSceneWithConfiguration:]_block_invoke_3 () #9 0x00000001c5bc16ec in -[FBScene _joinUpdate:block:completion:] () #10 0x00000001a64bab9c in -[_UISceneHostingController createSceneWithConfiguration:] () #11 0x00000001a64ba838 in -[_UISceneHostingController initWithAdvancedConfiguration:] () #12 0x00000001a64ba8cc in -[_UISceneHostingController initWithProcessIdentity:sceneSpecification:] () #13 0x00000001c05a8bd0 in -[SHSheetRemoteScene setupSceneHosting] () #14 0x00000001c05a88d0 in -[SHSheetRemoteScene activate] () #15 0x00000001c05f2e88 in -[SHSheetInteractor startSession] () #16 0x00000001c05ebc08 in -[SHSheetPresenter initWithRouter:interactor:] () #17 0x00000001c05de3c8 in +[SHSheetFactory createMainPresenterWithContext:] () #18 0x00000001c05d4dec in -[UIActivityViewController _createMainPresenterIfNeeded] () #19 0x00000001c05d6320 in -[UIActivityViewController _viewControllerPresentationDidInitiate] () #20 0x00000001a5a109c4 in -[UIViewController _presentViewController:withAnimationController:completion:] () #21 0x00000001a5a1311c in __63-[UIViewController _presentViewController:animated:completion:]_block_invoke () #22 0x00000001a5a0d248 in -[UIViewController _performCoordinatedPresentOrDismiss:animated:] () #23 0x00000001a5a0ceb4 in -[UIViewController _presentViewController:animated:completion:] () #24 0x00000001a5a0ccc0 in -[UIViewController presentViewController:animated:completion:] () #25 0x00000002001f3660 in -[UIPrintPanelViewController showSharePanelForPDFURL:] () In log throwing an error (I'm not 100% sure that is related - but last class in stack trace the same): failure in void _realizeSettingsExtension(__unsafe_unretained Class, __unsafe_unretained Class) (FBSSceneExtension.m:502) : could not convert "1" to an integer What I have is that big project with a lot of dependencies and etc.. Trying on clear project and it worked. (sharing simple local image with url). Testing on my project: With no controllers at all - check. With different approaches (htm content; pdf data, image local url) - check. With UIActivityViewController - check With day of UIPrintInteractionController creation (not a thread/related issue) - check. No other work can be done from my side (except rewrite 10years project). Help me please to debug it from private api prospective as I have no Idea what is happening. (trying to remove all appearances and all dependency - not easy task). Thanks
0
0
132
2w
How do you control the location of the menu in a UIContextMenu ?
class Coordinator: NSObject, UIContextMenuInteractionDelegate, ContextMenuManagerDelegate { var container: ContextMenuContainer var auxiliaryContent: AuxiliaryContent var menuItems: () -> [UIMenuElement] init(container: ContextMenuContainer) { self.container = container self.auxiliaryContent = container.auxiliaryContent self.menuItems = container.menuItems super.init() } func contextMenuInteraction( _ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint ) -> UIContextMenuConfiguration? { container.viewModel.contextMenuManager?.notifyOnContextMenuInteraction( interaction, configurationForMenuAtLocation: location ) return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in UIMenu(title: "", children: self?.menuItems() ?? []) } } func contextMenuInteraction( _ interaction: UIContextMenuInteraction, willDisplayMenuFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating? ) { container.viewModel.contextMenuManager?.notifyOnContextMenuInteraction( interaction, willDisplayMenuFor: configuration, animator: animator ) } func contextMenuInteraction( _ interaction: UIContextMenuInteraction, willEndFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating? ) { container.viewModel.contextMenuManager?.notifyOnContextMenuInteraction( interaction, willEndFor: configuration, animator: animator ) } func contextMenuInteraction( _ interaction: UIContextMenuInteraction, previewForHighlightingMenuWithConfiguration configuration: UIContextMenuConfiguration ) -> UITargetedPreview? { guard let targetView = interaction.view else { return nil } let bubbleWithTail = BubbleWithTailPath() let customPath = bubbleWithTail.path(in: targetView.bounds) let parameters = UIPreviewParameters() parameters.visiblePath = customPath return UITargetedPreview( view: targetView, parameters: parameters ) } func onRequestMenuAuxiliaryPreview(sender: ContextMenuManager) -> UIView? { let hostingController = UIHostingController(rootView: auxiliaryContent) hostingController.view.backgroundColor = .clear return hostingController.view } } i am trying to recreate apple's iMessage tapback reaction context menu. i have figured out how to attach an auxiliary view to the view with the menu, however the menu itself varies in position. if i bring up the context menu on a view below half the screen height, the menu appears above the view. else, it appears below. i need it to always be below.
0
0
111
2w
App Crashes on QuartzCore: CA::Layer::layout_if_needed(CA::Transaction*) + 504
I have facing an above crash for many users device running on iOS 17.6.1 mostly on iPad devices. I'm not sure why this happening only in 17.X. In Xcode Organizer unable to see this crash in any devices running on OS 18.x. Our app crashes got spiked due to this. I am unable to fix or reproduce the same. The crash log is not pointing to our app code to find the root cause and fix this issue. Have attached the crash log in this post also the crash log roles have mixed values Background & Foreground. But most of the crash is in background. Is this any crash related to system and that only solved by OS update? I have updated the app using Xcode 16 and 16.1 still facing this crash unable to symbolicate the crash report as well. Any ideas/solution how to solve this or how to proceed further. Have attached the entire crash log below. RoleBackgroundCrash.crash RoleForeGroundCrash.crash
0
0
138
2w
How can we make elements which are grouped accessible for automation
I have a stackview which have 2 labels class TextView: UIView { @IBOutlet private weak var stackView: UIStackView! { didSet { stackView.isAccessibilityElement = true stackView.accessibilityLabel = label1.text + label2.text } } @IBOutlet private weak var label1: UILabel! { didSet { label1.accessibilityIdentifier = "label1" } } @IBOutlet private weak var: UILabel!{ didSet { label2.accessibilityIdentifier = "label2" } } } My goal here is to have a combines accessibility label for the stackview and yet able to access the accessibilityIdentifier of child elements for automation.
0
0
814
2w
Defer system gestures in a WatchKit app
Hi, I'm making a WatchKit game app with SpriteKit and Objective-C, and I'm encountering an annoyance where system gestures, namely long-pressing the top and bottom edges to pull Notification/Control Center, interfere with the controls of the game. In iOS, this can be mitigated by using overriding preferredScreenEdgesDeferringSystemGestures in UIViewController, but I couldn't find any equivalent API in any WatchKit class, and searching for similar symbols only yielded a single private API (-[_UISystemAppearanceManager screenEdgesDeferringSystemGestures]) that isn't ever called on watchOS. Any idea how to achieve a similar effect on watchOS?
1
0
168
2w
Can we see Accessibility Identifiers alone of automation elements in swift which are not accessibility Elements
I want to expose few elements for accessibility alone and other for automation alone. But I can only accessibility elements in Accessibility Inspector but can't see Automation Elements self.view.accessibilityElements = [loginButton as Any, registerButton as Any, closeButton as Any] self.view.automationElements = [claimLabel as Any, loginButton as Any, registerButton as Any, intoductionImage as Any, closeButton as Any])
1
0
333
2w