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

Posts under UIKit tag

179 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

FirstResponderView/FirstResponderIndexPath in TableView
I found when I put a webView on the screen and then remove it, several properties in TableView including firstResponderView, FirstResponderIndexPath, and FirstResponderViewType have changed. These properties are hidden and I cannot change them. firstResponderView strong holds my cell, resulting in my cell not being able to call didEndDisplayCell when it slides out of the screen as expected. What should I do to avoid firstResponderView from strong holding my cell, or what should I do to release it?
1
0
360
Dec ’24
really modal alert in i(Pad)OS 18
I need a really modal alert, i.e., one which runs and allows the user interaction and closes and returns the selected option inside of a single method. (I need to serve an API which calls my callback, presuming I show an alert, get the user's decision, and return it from that very callback. The callback comes in the main thread.) What's the proper way to do this in i(Pad)OS 18+? Thanks! For reference, up to 17, the following code worked nicely; in 18, it does not anymore: volatile BOOL __block stillRuns=YES; UIAlertController* ac=[UIAlertController alertControllerWith... preferredStyle:UIAlertControllerStyleAlert]; [ac addAction:[UIAlertAction actionWith... handler:^(UIAlertAction * _Nonnull action) { stillRuns=NO; }]]; ... [UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:ac animated:YES completion:nil]; while (stillRuns) [NSRunLoop.currentRunLoop runUntilDate:[NSDate dateWithTimeIntervalSinceNow:.1]];
Topic: UI Frameworks SubTopic: UIKit Tags:
4
0
492
Dec ’24
App crash when using SwiftUI view in UICollectionView
Several users are seeing a crash that occurs when configureCell is called for a UICollectionView. This seems to occur specifically for cells that add SwiftUI views using UIHostedConfiguration. 0 libsystem_kernel.dylib 0xc1d4 __pthread_kill + 8 1 libsystem_pthread.dylib 0x7ef8 pthread_kill + 268 2 libsystem_c.dylib 0x77ad8 abort + 128 3 libswiftCore.dylib 0x3cc1a4 swift::fatalError(unsigned int, char const*, ...) + 134 4 libswiftCore.dylib 0x3cc1c4 swift::warningv(unsigned int, char const*, char*) + 30 5 libswiftCore.dylib 0x3cc810 swift_beginAccess + 538 6 libswiftCore.dylib 0x3cc864 swift_beginAccess + 84 7 SwiftUI 0x947a0 _UIHostingView._rootView.getter + 92 8 SwiftUI 0x94668 _UIHostingView.makeRootView() + 432 9 SwiftUI 0x943b8 _UIHostingView.updateRootView() + 264 10 SwiftUICore 0xa0d000 closure #1 in ViewRendererHost.updateGraph() + 204 11 SwiftUICore 0x1f1308 partial apply for thunk for @escaping @callee_guaranteed () -> () + 28 12 AttributeGraph 0x144a8 AGGraphWithUpdate + 84 13 SwiftUICore 0x4a5f60 @objc closure #1 in closure #1 in closure #1 in static Update.syncMain(_:) + 84 14 SwiftUICore 0x3620 wait_for_lock + 112 15 SwiftUICore 0x3588 _MovableLockLock + 68 16 SwiftUICore 0x5bb6d4 _ViewList_ReleaseElements.deinit + 64 17 SwiftUICore 0x5bb838 _ViewList_ReleaseElements.__deallocating_deinit + 16 18 libswiftCore.dylib 0x3d783c _swift_release_dealloc + 56 19 libswiftCore.dylib 0x3d8950 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 160 20 SwiftUICore 0x7cf7bc assignWithTake for _ViewList_View + 52 21 SwiftUICore 0x18dbe0 assignWithTake for ExclusiveGesture + 76 22 SwiftUI 0x13aff8 outlined assign with take of ModifiedContent<TableRowView, CollectionViewCellModifier> + 100 23 SwiftUI 0x1394fc specialized PlatformListCell<>.defaultConfigureContent(_:transaction:) + 296 24 SwiftUI 0xb8308 CollectionViewListDataSource.configureCell(_:transaction:context:) + 1200 25 SwiftUI 0xb8e20 ShadowListDataSource.configureCell(_:transaction:context:) + 1336 26 SwiftUI 0xb670c closure #1 in UICollectionViewListCoordinatorBase.updateListContents(_:) + 452 27 SwiftUI 0xead7b4 partial apply for closure #1 in ListCoreDataSource.visitRowAt<A>(_:visitor:) + 32 28 SwiftUI 0xb6160 partial apply for closure #1 in ListCoreDataSource.visitRowAt<A>(_:visitor:) + 16 29 SwiftUI 0x171e1c Optional.map<A, B>(_:) + 516 30 SwiftUI 0xb98d8 ListCoreDataSource.visitRowAt<A>(_:visitor:) + 1064 31 SwiftUI 0x33b3c ListCoreDataSource.visitContent<A>(atRow:visitor:) + 536 32 SwiftUI 0xb5478 UICollectionViewListCoordinatorBase.updateListContents(_:) + 1696 33 SwiftUI 0x942dac closure #1 in performUpdates #1 <A, B>() in UICollectionViewListCoordinatorBase.update(_:to:transaction:performDiff:) + 416 34 SwiftUI 0x3261cc thunk for @escaping @callee_guaranteed (@unowned Bool) -> () + 48 35 SwiftUI 0x94cf88 closure #1 in UpdateCoalescingCollectionView.performBatchUpdates(_:completion:) + 308 36 SwiftUI 0x3261cc thunk for @escaping @callee_guaranteed (@unowned Bool) -> () + 48 37 UIKitCore 0x2b9bbc -[UICollectionView _updateAnimationDidStop:finished:] + 1240 38 UIKitCore 0xa02c38 __118-[UICollectionView _startViewAnimationsWithContext:oldVisibleViews:viewAnimator:viewAnimationsCompletedDispatchGroup:]_block_invoke + 36 39 UIKitCore 0x7d788 __47-[UICollectionViewAnimation startWithAnimator:]_block_invoke_3 + 272 40 UIKitCore 0x7bfb0 __UIVIEW_IS_EXECUTING_ANIMATION_COMPLETION_BLOCK__ + 36 41 UIKitCore 0x7be94 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 624 42 UIKitCore 0x7abb0 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 436 43 UIKitCore 0x86f38 -[UIViewAnimationState animationDidStop:finished:] + 192 44 QuartzCore 0x4e3cc run_animation_callbacks(void*) + 132 45 libdispatch.dylib 0x40d0 _dispatch_client_callout + 20 46 libdispatch.dylib 0x129e0 _dispatch_main_queue_drain + 980 47 libdispatch.dylib 0x125fc _dispatch_main_queue_callback_4CF + 44 48 CoreFoundation 0x56204 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 49 CoreFoundation 0x53440 __CFRunLoopRun + 1996 50 CoreFoundation 0x52830 CFRunLoopRunSpecific + 588 51 GraphicsServices 0x11c4 GSEventRunModal + 164 52 UIKitCore 0x3d2eb0 -[UIApplication _run] + 816 53 UIKitCore 0x4815b4 UIApplicationMain + 340 The crashes started occurring in October and only for iOS 18 users (all versions from 18.0.0 to 18.2.0). We have several cell types that use SwiftUI views and I haven't been able to isolate the issue to any particular cell type. I have tried setting contentConfiguration = nil in prepareForReuse but this didn't help. Has there been a change in UICollectionView/UIHostingConfiguration in iOS 18? Any ideas on how this can be further investigated or resolved?
1
1
659
Jan ’25
How do I make a UIViewRepresentable beneath SwiftUI elements ignore touches to these elements?
Hello, and an early "Merry Christmas" to all, I'm building a SwiftUI app, and one of my Views is a fullscreen UIViewRepresentable (SpriteView) beneath a SwiftUI interface. Whenever the user interacts with any SwiftUI element, the UIView registers a hit in touchesBegan(). For example, my UIView has logic for pinching (not implemented via UIGestureRecognizer), so whenever the user holds down a SwiftUI element while touching the UIView, that counts as two touches to the UIView which invokes the pinching logic. Things I've tried to block SwiftUI from passing the gesture down to the UIView: Adding opaque elements beneath control elements Adding gestures to the elements above Adding gesture masks to the gestures above Converting eligible elements to Buttons (since those seem immune) Adding SpriteViews beneath those elements to absorb gestures So far nothing has worked. As long as the UIView is beneath SwiftUI elements, any interactions with those elements will be registered as a hit. The obvious solution is to track each SwiftUI element's size and coordinates with respect to the UIView's coordinate space, then use exclusion areas, but this is both a pain and expensive, and I find it hard to believe this is the best fix for such a seemingly basic problem. I'm probably overlooking something basic, so any suggestions will be greatly appreciated
0
0
397
Dec ’24
LazyVGrid inside a List Crashes on iPhone 15 Pro Max (iOS 18.x) Simulator
We've seen an issue when using a LazyVGrid inside a List. The app crashes with: Thread 1: Fatal error: <UpdateCoalescingCollectionView 0x600000ca0d20> is stuck in a recursive layout loop When debugging the issue, we were able to narrow down the issue to a minimum reproducible example below: struct ContentView: View { let columns = [ GridItem(.adaptive(minimum: 43)) ] var body: some View { List { LazyVGrid(columns: columns) { ForEach(0..<15) { value in if value == 0 { Text("a") } else { Color.clear } } } } } } The issue can be reproduced on iPhone 15 Pro Max and iOS 18.x specifically. In a production app we have a similar layout, but instead of GridItem(.adaptive) we use GridItem(.flexible).
3
2
537
Jan ’25
[UIViewController willMoveToParentViewController:] provides an incorrect navStack when popping a view controller in iPadOS 18.2
The Apple documentation for [UIViewController willMoveToParentViewController:] states, Called just before the view controller is added or removed from a container view controller. Hence, the view controller being popped should appear at the top of the navStack when willMoveToParentViewController: is called. In iPadOS 16 and 17 the view controller being popped appears at the top of the navStack when willMoveToParentViewController: is called. In iPadOS 18 the view controller being popped has already been (incorrectly) removed from the navStack. We confirmed this bug using iPadOS 18.2 as well as 18.0. Our app relies upon the contents of the navStack within willMoveToParentViewController: to track the user's location within a folder hierarchy. Our app works smoothly on iPadOS 16 and 17. Conversely, our customers running iPadOS 18 have lost client data and corrupted their data folders as a result of this bug! These customers are angry -- not surprisingly, some have asked for refunds and submitted negative app reviews. Why doesn't willMoveToParentViewController: provide the correct navStack in iPadOS 18.2?
2
0
622
Aug ’25
Snap to Item with Assistive Touch does not work when building an Game from Unity.
Hi all, I have been trying to get Apple's assistive touch's snap to item to work for a unity game built using Apple's Core & Accessibility API. The switch control recognises these buttons however, eye tracking will not snap to them. The case in which it needs to snap is when an external eye tracking device is connected and utilises assistive touch & assistive touch's snap to item. All buttons in the game have a AccessibilityNode with the trait 'Button' on them & an appropriate label, which, following the documentation and comments on the developer forum, should allow them to be recognised by snap to item. This is not the case, devices (iPads and iPhones) do not recognise the buttons as a snap to target. Does anyone know why this is the case, and if this is a bug?
0
0
557
Dec ’24
Strange Behavior of UITabBarController selectedIndex and UINavigationController pop
UITabBarController | | VC_Tab1 --------------------------- VC_Tab2 | | | | VC_Tab1_Child VC_Tab2_Child | (HeaderView) | (MyButton) The structure of the view controllers and views in the project is as described above. <case 1> self.navigationController?.popToRootViewController(animated: false) tabBarController.selectedIndex = 1 When popToRootViewController(animated: false) is called in VC_Tab1_Child, followed by setting the tab controller’s selectedIndex = 1, the following results are observed: viewWillAppear(_:), <VC_Tab2_Child> deinit, <VC_Tab1_Child> viewDidAppear(_:), <VC_Tab2_Child> The originally expected results are as follows viewWillDisappear(_:), <VC_Tab1_Child> viewDidDisappear(_:), <VC_Tab1_Child> deinit, <VC_Tab1_Child> deinit, <HeaderView> deinit, <MyButton> headerView.backButton.rx.tap -> Event completed headerView.backButton.rx.tap -> isDisposed viewWillAppear(_:), <VC_Tab2_Child> viewDidAppear(_:), <VC_Tab2_Child> The HeaderView belonging to VC_Tab1_Child was not deallocated, and the resources associated with that view were also not released. Similarly, VC_Tab1_Child.viewWillDisappear and VC_Tab1_Child.didDisappear were not called. <case 2> self.navigationController?.popToRootViewController(animated: false) DispatchQueue.main.async { tabBarController.selectedIndex = 1 } After performing the pop operation as shown in the code and waiting for a short period before testing, the expected results were generally achieved. (However, rarely, the results were similar to those observed when called without async.)” <case 3> self.navigationController?.popToRootViewController(animated: false) DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { tabBarController.selectedIndex = 1 } When a sufficient delay was ensured as described above, the expected results were achieved 100% of the time.” The abnormal behavior is more pronounced in iOS versions prior to 18 and varies depending on the iOS version. I couldn’t find any documentation explaining the unexpected behavior shown in the results above. What could be the cause? The simulation code is provided below. https://github.com/linusix/UITabBarController_Test2
0
0
264
Dec ’24
iOS 18 crash issue for unnecessary dequeuing
My code extension MyViewController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell { if let cell = collectionView.dequeueReusableCell( withReuseIdentifier: "CollectionViewCellID", for: indexPath ) as? CollectionViewCell { cell.setup() return cell } return UICollectionViewCell() } func collectionView( _ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath ) { // Unnecessary dequeue guard collectionView.dequeueReusableCell( withReuseIdentifier: "CollectionViewCellID", for: indexPath ) is CollectionViewCell else { return } // My action for selecting cell print("Cell Selected") } } Error: *** Assertion failure in -[UICollectionView _updateVisibleCellsNow:], UICollectionView.m:5673 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expected dequeued view to be returned to the collection view in preparation for display. When the collection view's data source is asked to provide a view for a given index path, ensure that a single view is dequeued and returned to the collection view. Avoid dequeuing views without a request from the collection view. For retrieving an existing view in the collection view, use -[UICollectionView cellForItemAtIndexPath:] or -[UICollectionView supplementaryViewForElementKind:atIndexPath:]. Solution: The problem was doing unnecessary dequeuing in didSelectItemAt when selecting the cell. In previous iOS like 17 or 16 or lower, it was allowed to dequeue where it is not really needed but from iOS 18, it may restricted to unnecessary dequeuing. So better to remove dequeue and use cellForItem(at) if we need to get cell from collection view. Example extension MyViewController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell { if let cell = collectionView.dequeueReusableCell( withReuseIdentifier: "CollectionViewCellID", for: indexPath ) as? CollectionViewCell { cell.setup() return cell } return UICollectionViewCell() } func collectionView( _ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath ) { guard collectionView.cellForItem(at: indexPath) is CollectionViewCell else { return } // My action for selecting cell print("Cell Selected") } }
0
0
3.5k
Dec ’24
UIDocumentPickerViewController Dismisses Automatically Twice When Selecting Multiple Files Quickly
Description: When using UIDocumentPickerViewController in iOS, if the user taps two or more files in quick succession, the picker view controller dismisses itself automatically twice. This results in an unintended behavior, leading to inconsistent screen states or redundant dismiss animations. Steps to Reproduce: Initialize a UIDocumentPickerViewController instance in UIDocumentPickerModeImport. UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeData] inMode:UIDocumentPickerModeImport]; documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFullScreen; documentPicker.allowsMultipleSelection = NO; [self presentViewController:documentPicker animated:YES completion:nil]; Launch the document picker. Quickly tap two or more files in succession. Expected Behavior: The UIDocumentPickerViewController should dismiss once and call the delegate method documentPicker:didPickDocumentsAtURLs: with the selected file(s). Actual Behavior: The UIDocumentPickerViewController automatically dismisses twice. This issue occurs even when no explicit call to dismissViewControllerAnimated: is made in the delegate method. Observed Results: The didPickDocumentsAtURLs: callback is invoked after the picker is already dismissed. During this process, unintended behavior such as multiple dismiss animations, view controller state corruption, or UI inconsistencies may occur. Impact: This issue disrupts the user experience and causes UI glitches when selecting documents. It prevents developers from having full control over dismiss behavior or mitigating the problem programmatically. Environment: iOS Version: iOS 15.0 and later (also reproduced on iOS 17.4) Device: Reproducible on multiple iPhone and iPad models Framework: UIKit Conclusion: This appears to be a system-level issue with UIDocumentPickerViewController. The automatic dismiss behavior is not correctlyhandling multiple taps, causing unintended dismiss events. Developers have no explicit way to prevent this behavior or gain full control over the dismissal process. We kindly request Apple to investigate and resolve this issue to ensure UIDocumentPickerViewController behaves as expected when interacting with multiple taps.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
1
331
Dec ’24
Crash with UITextView intelligenceCollectContent Apple Intelligence
Hello, I am using Xcode 15.3 and doesn't add any support for Apple Intelligence yet as it requires Xcode 16+. But I see many crashlogs related to Apple Intelligence, I assume crash is related to UITextView element of UIKit. Can you please help me to resolve this issue, how can I fix it? There are few lines of the crashlog, they are all similar. Thread 0 name: Thread 0 Crashed: 0 UIKitCore 0x0000000196692d74 specialized UITextView._intelligenceCollectContent(in:collector:) + 2748 (UITextView_IntelligenceSupport.swift:37) 1 UIKitCore 0x0000000196691eb0 @objc UITextView._intelligenceCollectContent(in:collector:) + 60 (<compiler-generated>:17) 2 UIIntelligenceSupport 0x000000026b91f1e4 UIIntelligenceElementCollector.performCollection(_:) + 424 (UIIntelligenceElementCollector.swift:46) 3 UIKitCore 0x0000000196473b70 specialized UIView._intelligenceElement(in:using:transformToRoot:) + 1440 (UIView_IntelligenceSupport.swift:132) 4 UIKitCore 0x000000019647a800 specialized UIView._intelligenceCollectElement(for:in:using:transformToRoot:) + 424 (UIView_IntelligenceSupport.swift:84) 5 UIKitCore 0x00000001964792ec @objc UIView._intelligenceCollectElement(for:in:using:transformToRoot:) + 136 (<compiler-generated>:77) 6 UIKitCore 0x0000000196472c20 closure #1 in UIView._intelligenceCollectSubelements(in:using:transformToRoot:) + 256 (UIView_IntelligenceSupport.swift:55) 7 UIIntelligenceSupport 0x000000026b91f728 UIIntelligenceElementCollector.performElementCollection(_:) + 424 (UIIntelligenceElementCollector.swift:61) v 8 UIKitCore 0x00000001964728f4 UIView._intelligenceCollectSubelements(in:using:transformToRoot:) + 928 (UIView_IntelligenceSupport.swift:54) 9 UIKitCore 0x0000000196473354 @objc UIView._intelligenceCollectSubelements(in:using:transformToRoot:) + 136 (<compiler-generated>:0) 10 UIKitCore 0x0000000196479810 closure #3 in UIView._intelligenceElement(in:using:transformToRoot:) + 256 (UIView_IntelligenceSupport.swift:165) 11 UIIntelligenceSupport 0x000000026b91fb54 UIIntelligenceElementCollector.performElementArrayCollection(_:) + 144 (UIIntelligenceElementCollector.swift:78) ... ... 225 UIIntelligenceSupport 0x000000026b8ee630 closure #1 in IntelligenceCollectionListener.collectFragments(_:) + 192 (IntelligenceCollectionListener.swift:60) 226 UIIntelligenceSupport 0x000000026b91b138 thunk for @escaping @callee_guaranteed () -> () + 36 227 CoreFoundation 0x000000019376b6e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 (CFRunLoop.c:1818) 228 CoreFoundation 0x0000000193759910 __CFRunLoopDoBlocks + 356 (CFRunLoop.c:1860) 229 CoreFoundation 0x00000001937595f4 __CFRunLoopRun + 2432 (CFRunLoop.c:3217) 230 CoreFoundation 0x0000000193758830 CFRunLoopRunSpecific + 588 (CFRunLoop.c:3434) 231 GraphicsServices 0x00000001df7381c4 GSEventRunModal + 164 (GSEvent.c:2196) 232 UIKitCore 0x00000001962beeb0 -[UIApplication _run] + 816 (UIApplication.m:3844)
3
0
744
Dec ’24
Identifying UIKit Api's failure
I have a UIKit application and it contains multiple UI components like UIWindow, UIView, UIButton, etc. I wanted to perform error handling for different OS calls in my application. For example, when creating a UIImage using init(named:) initialiser, the documentation clearly states that if the UIImage object cannot be created then the initialiser returns nil value. However, there are other UI components like UIButton (or like UIView), which when created using init(frame:) initialiser, the documentation does not mention for any return value. I wanted to know how to identify If the UIButton initialisation has failed? How is it that apple recommends should we handle these api's, If they fail to create a button. suppose If there is a case where it fails due to insufficient memory. Or is it that apple guarantees the Api's never fail?Is there some exception that is throw? I wanted somewhat detailed answer to these questions.
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
336
Dec ’24
Delay between animation and view accepting touch input
Hi! I was trying to add an animation to my SwiftUI view with UIKit, but after the animation runs there's a delay before the view will accept touch interactions. I thought it was because of the frame size of the view controller, but even after fixing that I still get the delay. Could anyone point me to where I might be going wrong, or if maybe using a UIKit modifier for the animation just doesn't work? Any help would be greatly appreciated! UIView: class BounceView: UIView { required init() { super.init(frame: .zero) } func bounceAnimation() { guard let piece = self.subviews.first else { return } UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0) { piece.frame.origin.x += 10 } } func bounceBack() { guard let piece = self.subviews.first else { return } UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0) { piece.frame.origin.x -= 10 } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } UIView controller: class BounceViewController: UIViewController { init(controller: UIViewController) { super.init(nibName: nil, bundle: nil) view = BounceView() addChild(controller) controller.view.translatesAutoresizingMaskIntoConstraints = false controller.view.backgroundColor = .clear view.addSubview(controller.view) controller.didMove(toParent: self) } // adjusts view to match bounds of child override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() let subviewFrame = self.view.subviews.first?.bounds ?? .zero view.frame = subviewFrame print(subviewFrame) self.updateViewConstraints() } func update(animated: Bool) { let bounceView = view as? BounceView if animated { bounceView?.bounceAnimation() } else { bounceView?.bounceBack() } } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } SwiftUI wrapper: struct BounceUIViewController: UIViewControllerRepresentable { private var controller: UIViewController @Binding var animated: Bool init(controller: UIViewController, animated: Binding<Bool>) { self.controller = controller self._animated = animated } func makeUIViewController(context: Context) -> BounceViewController { BounceViewController(controller: controller) } func updateUIViewController(_ uiViewController: BounceViewController, context: Context) { uiViewController.update(animated: animated) } } View extension: extension View { func bounce(animated: Binding<Bool>) -> some View { modifier(Bounce(animated: animated)) } } struct Bounce: ViewModifier { @Binding var animated: Bool init(animated: Binding<Bool>) { self._animated = animated } func body(content: Content) -> some View { BounceUIViewController(controller: content.uiViewController, animated: $animated) } }
1
0
643
Dec ’24
Error Handling for Widget APIs in iOS that neither raise any exception nor return any value?
I was looking out for the error handling for rendering the Widgets(like UIButton, UIVIew etc) on the screen in iOS. I am painting the screen programmatically using swift. Considering a simple Widget(like for say UIButton) when we try to create using its initializer and set some properties like 'setTitle' . These functions neither return any value upon success/failure nor in documentation they have mentioned about any exceptions which would be raised upon failure. https://developer.apple.com/documentation/uikit/uibutton/settitle(_:for:) So, how to do error handling here in this scenarios, in case the apis fail to due some reason, like memory issue? There must be some scenarios for these api failure.
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
437
Dec ’24
Help needed to understand the issues from the app
Hi, There are total three errors from the app running on the device. First one is right after the app starts running on the device: Could not create a sandbox extension for '/var/containers/Bundle/Application/D4CBF093-EFB1-43C5-996D-7D5CB04BF643/appadmob.app' Below second issue comes when I dismiss the Interstitial Ad First responder issue detected: non-key window attempting reload - allowing due to manual keyboard (first responder window is <UIWindow: 0x10d11c700; frame = (0 0; 414 896); hidden = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x301749300>; backgroundColor = <UIDynamicSystemColor: 0x3002b3080; name = _windowBackgroundColor>; layer = <UIWindowLayer: 0x3019b7960>>, key window is <QUIWindow: 0x10880db00; baseClass = UIWindow; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x3017276e0>; layer = <UIWindowLayer: 0x3019852f0>>) And the third issue below follows right after the second one: Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))" UserInfo={NSLocalizedFailureReason=((target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.rendering AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.networking AND target is not running or doesn't have entitlement com.apple.developer.web-browser-engine.webcontent))}> 0x118024480 - ProcessAssertion::acquireSync Failed to acquire RBS assertion 'WebProcess NearSuspended Assertion' for process with PID=19180, error: (null) Failed to terminate process: Error Domain=com.apple.extensionKit.errorDomain Code=18 "(null)" UserInfo={NSUnderlyingError=0x3019254a0 {Error Domain=RBSRequestErrorDomain Code=3 "No such process found" UserInfo={NSLocalizedFailureReason=No such process found}}} Also when I dismissed the interstitial ad, the screen looks greyed out, but when I touch the screen, the screen comes to normal. Could you please suggest any solution for the problems. Thanks,
2
0
2.7k
Dec ’24
SwiftUI Animation very Laggy on iOS 18 Release only
Dear Experts, I created a SwiftUI View (in a UIKit based project) whose objective is to display a short animation in the front of the user screen. I developed it 8 month ago in XCode 15 for iOS 17, no problems. But since iOS 18, I can observe huge lags on my animation only in Release app. The problem is not present in Debug app. I don't understand why this problem occurs, the animation is quite simple, it's just an offset deplacement. I tried many thing like: Show the animation with a UINavigationController Show the animation with a UIWindow Move the view with .position Remove the GeometryReader All other animation withAnimation and .animation Task and DispatchQueue Etc... I found that the laggy animation occurs when I set the Optimization Level for the Swift Compiler - Code Generation to Optimize for Speed [-O]. That's very strange because we had this option on Release for iOS 17 and we had no lags... I can share to you a Sample Repository with the configuration we have. https://github.com/Thibma/sample-animation-swiftui Today the only option I used is to develop this feature in UIKit but it's too bad to skip the SwiftUI opportunity. :/ If you have any ideas to resolve this, I take ! Thank you !
0
0
531
Dec ’24
Your browser preventing this app to open “URL”
Hi Apple developers, I am very new to XCode and Swift, I am planning to build an app for iOS from a web. I tried to use WKWebView to handle the web , I managed to redirect some of the links to Safari, however some button/links didn't trigger .linkActivated function and encounter the error as "Your browser preventing this app to open “URL”. If I copy the URL to Safari is able to open, I trying to research on web but can't find any related solution for my case. Here is the code in my app: import UIKit import WebKit import SafariServices class ViewController: UIViewController, WKNavigationDelegate { var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() // Initialize WKWebView let webConfiguration = WKWebViewConfiguration() //enable javascript webConfiguration.preferences.javaScriptEnabled = true webView = WKWebView(frame: self.view.frame, configuration: webConfiguration) webView.navigationDelegate = self self.view.addSubview(webView) // Load a web page as webview if let url = URL(string: "https://myurl") { let request = URLRequest(url: url) webView.load(request) } //console log webView.evaluateJavaScript("console.log('Button clicked!')") { result, error in if let error = error { print("Error executing JavaScript: \(error.localizedDescription)") } else { print("JavaScript result: \(String(describing: result))") } } } func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let url = navigationAction.request.url, navigationAction.navigationType == .linkActivated { // Check if URL is external and open it in Safari if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) decisionHandler(.cancel) // Prevent loading the link in the WebView } else { decisionHandler(.allow) // Allow loading if URL cannot be opened in Safari } } else { decisionHandler(.allow) // Allow the WebView to load the URL normally } } }
1
0
699
Jan ’25