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

UIKit Documentation

Post

Replies

Boosts

Views

Activity

How to make iPad app move to display show full-screen and center align
I wrote an app that can show live streaming. When using iPad, I can connect an external display and move app to display, that I can do what I want on my iPad and watch live streaming on external display using cable. But app moving to display is not always full screen, and on some displays it shows larger than the external display range that I should go to Settings -> Display & Brightness -> External Display -> Switching "Allow Display Mode Changes" to fix this issue. Are there APIs to make the App "move to display" programmatically, keep app full-screen, matching the external display's resolution on the External display?
2
0
174
2w
UIApplication.shared.open iOS 18
Making the call as: UIApplication.shared.open(websiteURL) doesn't open the browser and gives the following in the console: 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). However, making the call as: UIApplication.shared.open(websiteURL) { _ in } opens the browser and there is nothing in the cosole. Does someone understand why is this or if it's Apple's iOS 18 bug? In the iOS & iPadOS 18 RC Release Notes | Apple Developer Documentation there is a section around resolving this or something similar, unsure.
7
2
1.3k
2w
navigationItem.title now showing in iOS 18 UITabBarController
navigationItem.title does not display on the first view controller in the new UITabBarController on iPad. Also, if I set navigationItem.titleMenuProvider an empty space is displayed. Everything displays as expected if it isn’t the first view controller. let tabBarController = UITabBarController(tabs: [ UITab(title: "Tab 1", image: nil, identifier: "tab1", viewControllerProvider: { _ in return UINavigationController(rootViewController: ViewController()) }) ]) class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "First" navigationItem.titleMenuProvider = { suggestions in return UIMenu(children: [ UIAction(title: "Option 1", handler: { _ in self.navigationController?.pushViewController(SecondViewController(), animated: true) }), UIAction(title: "Option 2", handler: { _ in }) ]) } } } class SecondViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "Second" navigationItem.titleMenuProvider = { suggestions in return UIMenu(children: [ UIAction(title: "Option 1", handler: { _ in }), UIAction(title: "Option 2", handler: { _ in }) ]) } } }
3
0
161
2w
Save large PDF file with UIDocument
Hi, I'm working with UIDocument to store a PDF file. This is code I use for saving a file. document.close(completionHandler: { (success) in if success { document.save(to: url, for: .forOverwriting, completionHandler: { (success) in if success { print("Saved file successfully") } }) } }) This code works well with a small file size. But if it's a large file like 100MB, it takes around 2-5 minutes to save the file. Is there a way to save file with the changes only? Or create an auto save function triggered whenever the user edit the file?
2
0
143
2w
If you cancel a print job using AirPrint while the printer is turned off, the print center remains on the app switcher and subsequent printing cannot be performed correctly.
-Environment iPad:10th、iOS:17.6.1、Printer:EPSON PX-S730 -Question Is this phenomenon due to iOS specifications? Restarting the iPad solves the problem, but I don't think it's best practice to restart it every time you reproduce it. Please let me know if you have a good solution. -Problem I am developing a print preview screen using AirPrint's print method. If you submit a print job using AirPrint on an iPad while the printer is turned off and then cancel it, the print center remains on the app switcher. After that, when I turned on the printer, I was no longer able to print using AirPrint on my iPad. When using AirPrint's API "print" and when printing by launching AirPrint from Safari, we have confirmed the same behavior in both cases. -How to reproduce Turn off the printer Print from iPad to printer using AirPrint Launch the print center from the app switcher, cancel the print job, and set the number of print jobs to 0. When you start the app switcher, the Print Center app remains. In step 4, turn on the printer and print from the iPad to the printer using AirPrint. When you start Print Center from the app switcher, the print job status becomes "Waiting" and the print job is not executed. -Expected result When there are no print jobs on the print center, the print center is closed on the app switcher. You can print from your iPad to the printer using AirPrint, and then print from the printer. -Actual results When there are no print jobs on the print center, the print center remains on the app switcher without being closed. In the above situation, when printing from the iPad to the printer using AirPrint, the printer does not print. When I start the print center, the print job status is "Waiting" and is queued. -Code printInfo.jobName = "Print Job" printController.printInfo = printInfo let pdfURL = Bundle.main.url(forResource: "sample", withExtension: "pdf")! printController.printingItem = pdfURL let printer = UIPrinter(url: printerUrl) printController.print(to: printer, completionHandler: { [self] printController, completed, error in if(error != nil){ print("error"). }else if completed{ print("completed") //this scenario handles completion response }else{ print("cancel") } }) -Link of API used Apple Developer-AirPrint-print -Similar inquiries Apple Developer Forum - Print Center on my iPhone shows a pending document to print and I can't get rid of it
1
0
221
2w
macOS Sequoia – NSToolbar on Catalyst disappeared
Hello, I have a macOS Catalyst app that I now began updating and building against the iOS 18/macOS Sequoia SDKs. Most things appear to be working just fine as before, apart from my NSToolbar. At the root of my app I am presenting a UISplitViewController which gets a custom SidebarViewController and a UITabBarController as its viewControllers. Then at same point in the apps lifecycle the UITabBarController presents another ViewController modally. I then associate the controllers window with a custom NSToolbar like this: let toolbar = NSToolbar(identifier: "mainToolbar") toolbar.displayMode = .iconAndLabel toolbar.delegate = self toolbar.allowsUserCustomization = false titleBar.toolbarStyle = .automatic titleBar.titleVisibility = .hidden titleBar.toolbar = toolbar I also disable automatic NSToolbar hosting via: https://developer.apple.com/documentation/uikit/uinavigationbardelegate/3987959-navigationbarnstoolbarsection (returning .none). Now all of this worked fine on macOS Sonoma and previous versions but on Sequoia my custom toolbar refuses to show up. My suspicion is that is has something to do with the new tab and sidebar behaviour introduced with the new SDKs (https://developer.apple.com/documentation/uikit/uinavigationbardelegate/3987959-navigationbarnstoolbarsection). For now within my UITabBarController I was able to revert to the old look using: if #available(iOS 18.0, *) { mode = .tabSidebar sidebar.isHidden = true isTabBarHidden = true } This result in a look similar to the previous macOS version but my NSToolbar unfortunately remains hidden. Is there an easy fix for this? Since I am a solo developer I would prefer to spend my available resources currently on other features and adopt the new tab/sidebars a couple months down the line. Appreciate any help and hints, thanks! There used to be a toolbar here on the right side. ↑
2
1
227
2w
UIButton starts out focused but can't navigate back to it
I'm an experienced iOS developer but new to tvOS, and I'm finding the focus engine to be somewhat confounding. My app launches with a UINavigationController, whose root view is a UITableViewController. When I select a row, a UIViewController is pushed. That view controller contains a bunch of nested UICollectionViews. One of the collection view cells contains 3 UIButtons. When the view first appears, the first of those (Button1) has focus. I can move focus from Button1 to Button2, and from Button2 to Button3. I can also go back from Button3 to Button2. But I cannot navigate back to Button1, and I'm trying to figure out why. I have focus logging turned on. It's very verbose, but here are the parts that seem useful to me: When the view controller displays initially, I see Updating focus from <UITableViewCell: 0x104841a00> to <DXETV.CustomButton: 0x104232610> in focus system <UIFocusSystem: 0x60000370c900>. The result of the focus update was determined from the following preferred focus search: | | Starting preferred focus search. | <UINavigationController: 0x10600f000> | └ <DXETV.RenderExampleViewController: 0x10484ae00> | └ <DXETV.RenderExampleView: 0x10421ab70> | └ <DXETV.LayoutElementView: 0x107021000> | └ <DXETV.LayoutCollectionView: 0x10707d200> | └ <DXETV.LayoutViewCell: 0x10681ee00> | └ <DXETV.LayoutElementView: 0x106862000> | └ <DXETV.LayoutCollectionView: 0x106865a00> | └ <DXETV.LayoutViewCell: 0x106851000> | └ <DXETV.LayoutElementView: 0x104891800> | └ <DXETV.LayoutCollectionView: 0x10488da00> | └ <DXETV.LayoutViewCell: 0x1048de600> | └ <DXETV.CustomButton: 0x104232610> | (info) It's focusable! | This seems right... focus moves from the table view cell to Button1, and this is he view hierarchy I expect. Then we see Creating focus scroll animator entry for environment <DXETV.LayoutCollectionView: 0x10707d200> This is the topmost collection view. This is followed by many lines about locking and unlocking this collection view, followed by Removing focus scroll animator entry for environment <DXETV.LayoutCollectionView: 0x10707d200> I don't know if this is normal or not. After I move focus from Button1 to Button2, I see Updating focus with context <UIFocusUpdateContext: 0x6000033200a0: previouslyFocusedItem=<DXETV.CustomButton 0x104232610>, nextFocusedItem=<DXETV.CustomButton 0x104312900>, focusHeading=Down>: Moving focus from <DXETV.CustomButton: 0x104232610> to <DXETV.CustomButton: 0x104312900> in focus system <UIFocusSystem: 0x60000370c900>. Which seems correct. When I move focus from Button2 to Button3, I get this, which is now expected: Updating focus with context <UIFocusUpdateContext: 0x60000330c5a0: previouslyFocusedItem=<DXETV.CustomButton 0x104312900>, nextFocusedItem=<DXETV.CustomButton 0x1043134d0>, focusHeading=Down>: Moving focus from <DXETV.CustomButton: 0x104312900> to <DXETV.CustomButton: 0x1043134d0> in focus system <UIFocusSystem: 0x60000370c900>. Followed by another round of creating and removing a focus scroll animator entry, this time for the middle collection view. Moving from Button3 back to Button2 also looks as expected: Updating focus with context <UIFocusUpdateContext: 0x600003318f00: previouslyFocusedItem=<DXETV.CustomButton 0x1043134d0>, nextFocusedItem=<DXETV.CustomButton 0x104312900>, focusHeading=Up>: Moving focus from <DXETV.CustomButton: 0x1043134d0> to <DXETV.CustomButton: 0x104312900> in focus system <UIFocusSystem: 0x60000370c900>. But here, everything stops. When I press the up arrow again to go back to Button1, nothing happens. Nothing is printed to the console, and the focused button does not change. Any hints as to what may be wrong or how to debug this further would be most appreciated!!!
0
0
192
3w
highlightPreviewForItemAt for Collection View not working at all
Hello, I have collection view with context menu using contextMenuConfigurationForItemAt and I wanted to customize the preview, when user long presses and context menu is shown. Something maybe like in the Music app when you long press on an album it shows the album in bigger size... I found some snippets online for highlightPreviewForItemAt and dismissalPreviewForItemAt but it just doesn't work. As soon as a implemented these delegate methods, nothing happens when I long press, not even the standard preview with context menu. These two methods aren't being called at all. Do I need to do something else? Do I need the previewProvider when creating the context menu? It is my understanding that that is needed only when the item should also open further detail on tap - which is something I don't need and want. Below is my relevant implementation: private func shareMenuConfiguration(for itemAt: URL, indexPath: IndexPath) -> UIContextMenuConfiguration { let share = UIAction(title: "Share".localized(), image: UIImage(systemName: "square.and.arrow.up")) { [unowned self] _ in let shareVC = UIActivityViewController(activityItems: [itemAt], applicationActivities: nil) if let cell = collectionView.cellForItem(at: indexPath) { shareVC.popoverPresentationController?.sourceView = cell.contentView shareVC.popoverPresentationController?.sourceRect = cell.contentView.bounds } self.present(shareVC, animated: true) } return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in UIMenu(title: "", children: [share]) } } func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, highlightPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { guard let item = datasource.itemIdentifier(for: indexPath), let cell = collectionView.cellForItem(at: indexPath) as? GalleryImageCell else { return nil } let parameters = UIPreviewParameters() let visibleRect = cell.contentView.bounds.insetBy(dx: 1/3, dy: 1/3) let visiblePath = UIBezierPath(roundedRect: visibleRect, cornerRadius: 4) parameters.visiblePath = visiblePath return UITargetedPreview( view: cell.contentView, parameters: parameters, target: .init(container: collectionView, center: collectionView.convert(cell.contentView.center, from: cell.contentView)) ) } func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, dismissalPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { guard let item = datasource.itemIdentifier(for: indexPath), let cell = collectionView.cellForItem(at: indexPath) as? GalleryImageCell else { return nil } let parameters = UIPreviewParameters() let visibleRect = cell.contentView.bounds.insetBy(dx: 1/3, dy: 1/3) let visiblePath = UIBezierPath(roundedRect: visibleRect, cornerRadius: 4) parameters.visiblePath = visiblePath return UITargetedPreview( view: cell.contentView, parameters: parameters, target: .init(container: collectionView, center: collectionView.convert(cell.contentView.center, from: cell.contentView)) ) } Thanks!
0
0
182
3w
RoomPlan: textures for walls and floors.
After scanning the room I use the .export method passing a ModelProvider. Then I import the USDZ into a SCNView and continue processing the scene: I would like to apply a texture to the walls and floor, but I can't do it for the walls and floor because they don't contain the TextureCoordinates. Creating them from the USDZ file is not easy. I tried to combine the CapturedRoom data for the walls and floor only, adding the TextureCoordinates. I'm managing, but I'm struggling a lot. Isn't there an easier way to do it? Is there a ModelProvider planned for surfaces in the future? If so, where can I access the RoomPlan beta documentation?
1
0
207
3w
[iOS 18] UITabBarController disable new switching animation
Hello ! Since iOS/iPadOS 18 there is a new switch transition between tabs in UITabBarController where is a little zoom of the selected UIViewController. At first, I thought that was a bug but I found the same animation on the Apple's apps (like music, shortcuts...) On my app, this animation produce a little flash/blink white before zooming, it's not smooth like on Apple's apps. I searched on documentation but I didn't found any topics about how to disable it or handled it better. Is this possible to disabled it ?
4
0
825
3w
Incorrect behaviour when trying to change focus to a focused view inside UIPageViewController
We are experiencing difficulties with keyboard navigation focus within a view contained inside a UIPageViewController. The intended keyboard navigation sequence does not function as expected. Expected Behavior: Pressing the Tab key once should move the focus to the UIPageViewController, allowing the use of the Up and Down arrow keys to navigate between pages. Pressing the Tab key a second time should shift the focus outside the UIPageViewController Pressing the Tab key a third time should move the focus back to the UIPageViewController. Actual Behavior: The focus does not shift as described above. Have sent a sample Xcode project to Apple demonstrating the issue (unfortunately it doesn't allow me to attach the zipped project here for some reason). STEPS TO REPRODUCE Set a breakpoint at viewDidAppear (line 44, MyViewController) Run the app, wait until it stops, and run the command in the lldb debugger Command: po UIFocusDebugger.checkFocusability(for: pager.viewControllers!.first!.view.subviews.first!) Output: The following issues were found that would prevent this item from being focusable: - ISSUE: One or more ancestors have issues that may be preventing this item from being focusable. Details: <_UIQueuingScrollView: 0x104826a00>: - ISSUE: This view returns YES from -canBecomeFocused, which will prevent its subviews from being focusable. <_UIPageViewControllerContentView: 0x103d07be0>: - ISSUE: This view returns YES from -canBecomeFocused, which will prevent its subviews from being focusable.
2
0
177
3w
UIPasteboard.general.string not propagating to other devices when idle
I'm working on an app that uses UIPasteboard.general.string = "my text here" to copy text to the user's pasteboared so that they can then paste from another device. I'm doing this periodically based on conditions - so every 10-20 seconds, I have a new string to copy to the pasteboard. Consistently after 2 minutes, this stops working - the pasteboard on the local device updates, but my other devices don't receive the new pasteboard content. If I touch the screen of the device running my app to 'wake it up', it suddenly works again for another 2 minutes. I've tried UIApplication.shared.idleTimer = false but it has had no effect. Is there a way to keep the universal pasteboard working without constant app interaction?
0
0
249
3w
iPadOS in iOS18 with new UITabBarController ... UIBarButtonItems disappear
I have an iPad app using the new UITabBarController on iPadOS18, which is suffering from a new issue from the new layout. Within my tabs, I have a UISplitViewController, with a 2 column layout. If I load the app, it works ok, but if I put the app in the background, and then bring it to foreground, the navigation bar buttons and title just disappear from the splitView controller’s primary view controller. Before going to background: After coming back from background: I also get the following layout issues posted in the debugger consoler: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<NSLayoutConstraint:0x600002106ee0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing <= UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide'.trailing (active)>", "<NSLayoutConstraint:0x600002137520 H:|-(590)-[UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'](LTR) (active, names: '|':_UINavigationBarContentView:0x103d18810 )>", "<NSLayoutConstraint:0x600002137610 UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'.width == 0 (active)>", "<NSLayoutConstraint:0x6000021414a0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing >= UILayoutGuide:0x600003b00a80'TabBarGuide(0x103d18810)'.trailing (active)>", "<NSLayoutConstraint:0x600002148e10 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x103d18810.width == 585 (active)>", "<NSLayoutConstraint:0x600002107570 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide']-(20)-|(LTR) (active, names: '|':_UINavigationBarContentView:0x103d18810 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002106ee0 UILayoutGuide:0x600003b088c0'TitleView(layout=0x103d18d40)'.trailing <= UILayoutGuide:0x600003b08c40'UIViewLayoutMarginsGuide'.trailing (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. I filed a bug report: FB14971801 Is there something I can do avoid this? It'll make my app pretty unusable if the bar button items just disappear every time the user puts the app in the background and then foregrounds the app.
1
0
383
4w
UITextView scrolling indicator cut off at top
Sample app A collection view controller with list layout, 1 section and 1 row. The cell's content view contains a text view. class ViewController: UICollectionViewController { var snapshot: NSDiffableDataSourceSnapshot<Section, String> { var snapshot = NSDiffableDataSourceSnapshot<Section, String>() snapshot.appendSections([.main]) snapshot.appendItems(["one", "two"], toSection: .main) return snapshot } var dataSource: UICollectionViewDiffableDataSource<Section, String>? enum Section { case main } init() { super.init(collectionViewLayout: .init()) collectionView.collectionViewLayout = createLayout() configureDataSource() // more likely and automatically avoid unpleasant animations on iOS 15 by configuring the data source in the init rather than in view did load } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in let textView = UITextView() textView.font = .systemFont(ofSize: UIFont.labelFontSize) cell.contentView.addSubview(textView) textView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ textView.topAnchor.constraint(equalTo: cell.contentView.topAnchor, constant: 8), textView.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor, constant: -8), textView.leadingAnchor.constraint(equalTo: cell.contentView.leadingAnchor, constant: cell.directionalLayoutMargins.leading), textView.trailingAnchor.constraint(equalTo: cell.contentView.trailingAnchor, constant: -cell.directionalLayoutMargins.trailing) ]) } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } dataSource?.apply(self.snapshot, animatingDifferences: false) } func createLayout() -> UICollectionViewLayout { return UICollectionViewCompositionalLayout { section, layoutEnvironment in let config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } } Question 1 Can anybody edit the provided sample code so that the text view's vertical indicator inset is not cut off at the top? Question 2 It seems to me that Apple has successfully implemented text views inside table view cells: can anybody provide Apple documentation as per how to do so? What I've tried and didn't work textView.verticalScrollIndicatorInsets.top = 30 // does nothing Adding the text view to a custom view and the view to the cell's content view textView.contentInset = .zero textView.scrollIndicatorInsets = .zero textView.textContainerInset = .zero textView.textContainer.lineFragmentPadding = 0 Centering the text view vertically and constraining its height to that of the content view with an 8 points constant to leave some padding Constraining the top and bottom anchors of the text view to the cell's layout margins guide's top and bottom anchors Constraint I need the text view to have some padding from the top and bottom of the cell for aesthetic reasons.
3
0
225
Aug ’24
How can I use the F8 play/pause key to control media playback in Catalyst?
I have a Catalyst app that plays audio via AVQueuePlayer, and I'd like to use the system play/pause key (F8 on my MacBook Pro keyboard) to play and pause it. It doesn't seem to work automatically, and if I hook up a UIKeyCommand using UIKeyInputF8, it works with Fn-F8, not F8 on its own. It does seem to work in Overcast's Mac app, but I think that's an iPad app for Mac, not Catalyst, so it's probably going through whatever system pathway that the Lock Screen controls would be using on iOS. How do I make this work on Catalyst?
1
0
276
Aug ’24