Hi,
I have an existing Mac app on the App Store with a couple of widgets as part of the app. I want to now add a new widget to the WidgetBundle. When I build the updated app with Xcode, and then run the updated app, the widgets list doesn't seem to get updated in Notification Center or in the WidgetKit Simulator.
I do have the App Store version installed in the /Applications folder as well, so there might be some conflict. What's the trick to getting the widgets list to run the debug version?
Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am new to the idea of Siri Shortcuts and App Intents. What I want to do is use Siri to run a function in my app.
Such as saying to Siri Zoom in map and that will then call a function in my app where I can zoom in the map. Similarly, I could say Zoom out map and it would call a function to zoom out my map.
I do not need to share any sort of shortcut with the Shortcuts app.
Can someone please point me in the right direction for what type of intents I need to use for this?
Xcode 16 iOS18 WKWebView里包含http图片时无法显示
Topic:
UI Frameworks
SubTopic:
UIKit
I'd like to support different template views within a ViewThatFits for items within a list, allowing the list to optimize its layout for different devices.
Within the child views is a Text view that is bound to the name of an item. I'd rather the Text view simply truncate the text as necessary although it instead is influencing which view is chosen by ViewThatFits. I'd also rather not artificially set the maxWidth of the Text view as it artificially limits the width on devices where it's not necessary (e.g. iPad Pro vs. iPad mini or iPhone).
Any guidance or suggestions on how this can be accomplished as it looks very odd for the layout of one row in the list to be quite different than the rest of the rows.
My Mac app crashes for some users inside VideoToolbox, and I'm not sure what to do with that, and how to fix it.
Here are couple of examples that repeating again and again for macOS 15.*
Thread 10 Crashed:
0 libsystem_pthread.dylib 0x000000018535a8e0 0x185359000 + 6368
1 VideoToolbox 0x0000000194f3e218 0x194f28000 + 90648
2 VideoToolbox 0x00000001951de384 0x194f28000 + 2843524
3 libxpc.dylib 0x000000018506f2c0 0x185060000 + 62144
4 libxpc.dylib 0x000000018506da14 0x185060000 + 55828
5 libdispatch.dylib 0x00000001851ad674 0x1851a9000 + 18036
6 libdispatch.dylib 0x00000001851c9c88 0x1851a9000 + 134280
7 libdispatch.dylib 0x00000001851b4a38 0x1851a9000 + 47672
8 libdispatch.dylib 0x00000001851ca9dc 0x1851a9000 + 137692
9 libdispatch.dylib 0x00000001851b4a38 0x1851a9000 + 47672
10 libdispatch.dylib 0x00000001851b5764 0x1851a9000 + 51044
11 libdispatch.dylib 0x00000001851bf4cc 0x1851a9000 + 91340
12 libdispatch.dylib 0x00000001851bf260 0x1851a9000 + 90720
13 libsystem_pthread.dylib 0x00000001853602e4 0x185359000 + 29412
14 libsystem_pthread.dylib 0x000000018535b0fc 0x185359000 + 8444
and
Thread 10 Crashed:
0 libsystem_pthread.dylib 0x00000001981fc364 0x1981fb000 + 4964
1 VideoToolbox 0x00000001a85f9964 0x1a81e8000 + 4266340
2 VideoToolbox 0x00000001a847a840 0x1a81e8000 + 2697280
3 libxpc.dylib 0x0000000197f09830 0x197efb000 + 59440
4 libxpc.dylib 0x0000000197f0812c 0x197efb000 + 53548
5 libdispatch.dylib 0x00000001980638a4 0x198048000 + 112804
6 libdispatch.dylib 0x00000001980660e8 0x198048000 + 123112
7 libdispatch.dylib 0x00000001980521b8 0x198048000 + 41400
8 libdispatch.dylib 0x0000000198066e4c 0x198048000 + 126540
9 libdispatch.dylib 0x00000001980521b8 0x198048000 + 41400
10 libdispatch.dylib 0x0000000198052e60 0x198048000 + 44640
11 libdispatch.dylib 0x000000019805be30 0x198048000 + 81456
12 libdispatch.dylib 0x000000019805bbf0 0x198048000 + 80880
13 libsystem_pthread.dylib 0x0000000198201c0c 0x1981fb000 + 27660
14 libsystem_pthread.dylib 0x00000001981fcb80 0x1981fb000 + 7040
and this one is for macOS 14
Thread 10 Crashed:
0 VideoToolbox 0x000000018f12ac90 0x18f11d000 + 56464
1 VideoToolbox 0x000000018f130a80 0x18f11d000 + 80512
2 VideoToolbox 0x000000018f131090 0x18f11d000 + 82064
3 VideoToolbox 0x000000018f130f94 0x18f11d000 + 81812
4 Remote for Mac 0x00000001048d521c 0x1048d0000 + 21020
5 Foundation 0x000000018174796c 0x181709000 + 256364
6 Foundation 0x000000018174782c 0x181709000 + 256044
7 Foundation 0x00000001817477bc 0x181709000 + 255932
8 Foundation 0x0000000181746b64 0x181709000 + 252772
9 Foundation 0x00000001817468d4 0x181709000 + 252116
10 Foundation 0x00000001817467c4 0x181709000 + 251844
11 libdispatch.dylib 0x00000001803b0470 0x18039d000 + 78960
12 libdispatch.dylib 0x00000001803a13e8 0x18039d000 + 17384
13 libdispatch.dylib 0x00000001803a48ec 0x18039d000 + 30956
14 libdispatch.dylib 0x00000001803a3f08 0x18039d000 + 28424
15 libdispatch.dylib 0x00000001803b2ea8 0x18039d000 + 89768
16 libdispatch.dylib 0x00000001803b36b8 0x18039d000 + 91832
17 libsystem_pthread.dylib 0x000000018054dfd0 0x18054b000 + 12240
18 libsystem_pthread.dylib 0x000000018054cd28 0x18054b000 + 7464
I have a popover/sheet in iOS which allows users to search and add items to a list. When the sheet is shown, the search should always be active.
I am using searchable on a NavigationStack inside the sheet. I am using the isPresented parameter to activate search.
My issue is with the animation of the search activation. Even if I use...
isPresented: .constant(true)
...the search isn't activated until the sheet has completed it's entrance animation, resulting in two stages of animation.
I can't add a video here, but the two images below show the steps I am seeing. First a slide up animation, with the search in the navigation drawer, then a second animation, once the sheet is fully in place, as the search becomes active.
Is it possible to merge these two animations, so search is in place when the sheet animates up?
Topic:
UI Frameworks
SubTopic:
SwiftUI
I have an application named "XY" that has been launched in several countries. Now, I intend to launch it in Turkey, but we are facing legal issues preventing us from using "XY" as the app's display name. Following the documentation, I localized the app's display name to "ZX" for both Turkish and English (Turkey). However, when users change their device settings, they do not see an option for English (Turkey) language selection. I assumed that for Turkish users, English (Turkey) would be the default language, but this is not the case. Could someone please assist me in resolving this issue? I've investigated options for localizing the display name based on region, but it seems that this functionality isn't feasible on iOS. In contrast, it's relatively straightforward to achieve on Android platforms.
Description:
When initiating the print flow via UIPrintInteractionController, and no printer is initially connected, iOS displays all possible paper sizes in the paper selection UI. However, if a printer connects in the background after this view is shown, the list of paper sizes does not automatically refresh to reflect only the options supported by the connected printer.
If the user selects an incompatible paper size (one not supported by the printer that has just connected), the app crashes due to an invalid configuration.
Steps to Reproduce:
Launch the app and navigate to the print functionality.
Tap the Print button to invoke UIPrintInteractionController.
At this point, no printer is yet connected. iOS displays all available paper sizes.
While the paper selection UI is visible, the AirPrint-compatible printer connects in the background.
Without dismissing the controller, the user selects a paper size (e.g., one that is not supported by the printer).
The app crashes.
Expected Result: App should not crash
Once the printer becomes available (connected in the background), the paper size options should refresh automatically.
The list should be filtered to only include sizes that are compatible with the connected printer.
This prevents the user from selecting an invalid option, avoiding crashes.
Actual Result: App crashes
The paper size list remains unfiltered.
The user can still select unsupported paper sizes.
Selecting an incompatible option causes the app to crash, due to a mismatch between UI selection and printer capability.
Topic:
UI Frameworks
SubTopic:
UIKit
I am experiencing memory leaks in my iOS app that seem to be related to an issue between UIInputView and _UIInputViewContent. After using the memory graph, I'm seeing that instances of these objects aren't being deallocated properly.
The UIInputViewController whichs holds the inputView is being deallocated properly along with its subviews.I have tried to remove all of UIInputViewController's subviews and their functions but the uiInputView is not being deallocated.
The current setup of my app is a collectionView with multiple cell,each possessing a textfield with holds a UIInputViewController.When i scroll up or down,the views are being reused as expected and the number of UIInputViewController stays consistent with the number of textfields.However the number of inputView keeps increasing referencing solely _UIInputViewContent.
class KeyboardViewController: UIInputViewController {
// Callbacks
var key1: ((String) -> Void)?
var key2: (() -> Void)?
var key3: (() -> Void)?
var key4: (() -> Void)?
private lazy var buttonTitles = [
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"]
]
override func viewDidLoad() {
super.viewDidLoad()
setupKeyboard()
}
lazy var mainStackView: UIStackView = {
let mainStackView = UIStackView()
mainStackView.axis = .vertical
mainStackView.distribution = .fillEqually
mainStackView.spacing = 16
mainStackView.translatesAutoresizingMaskIntoConstraints = false
return mainStackView
}()
private func setupKeyboard() {
let keyboardView = UIView(frame:CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 279.0))
keyboardView.addSubview(mainStackView)
NSLayoutConstraint.activate([
mainStackView.topAnchor.constraint(equalTo: keyboardView.topAnchor, constant: 16),
mainStackView.leadingAnchor.constraint(equalTo: keyboardView.leadingAnchor, constant: 0),
mainStackView.trailingAnchor.constraint(equalTo: keyboardView.trailingAnchor, constant: -24),
mainStackView.bottomAnchor.constraint(equalTo: keyboardView.bottomAnchor, constant: -35)
])
// Create rows
for (_, _) in buttonTitles.enumerated() {
let rowStackView = UIStackView()
rowStackView.axis = .horizontal
rowStackView.distribution = .fillEqually
rowStackView.spacing = 1
// Create buttons for each row
for title in rowTitles {
let button = createButton(title: title)
rowStackView.addArrangedSubview(button)
}
mainStackView.addArrangedSubview(rowStackView)
}
self.view = keyboardView
}
private func createButton(title: String) -> UIButton {
switch title {
///returns a uibutton based on title
}
}
// MARK: - Button Actions
@objc private func numberTapped(_ sender: UIButton) {
if let number = sender.title(for: .normal) {
key1?(number)
}
}
@objc private func key2Called() {
key2?()
}
@objc private func key3Called() {
key3?()
}
@objc private func key4Called() {
key4?()
}
deinit {
// Clear any strong references
key1 = nil
key2 = nil
key3 = nil
key4 = nil
for subview in mainStackView.arrangedSubviews {
if let stackView = subview as? UIStackView {
for button in stackView.arrangedSubviews {
(button as? UIButton)?.removeTarget(self, action: nil, for: .allEvents)
}
}
}
mainStackView.removeFromSuperview()
}
}
Environment
iOS 16.3
Xcode 18.3.1
Any insights would be greatly appreciated as this is causing noticeable memory growth in my app over time.
I'm trying to use @Query in a wrapper view around a Button to keep a macOS menu command up to date but I keep getting
Set a .modelContext in view's environment to use Query
even though
@Environment(\.modelContext) private var modelContext
is part of the views.
Topic:
UI Frameworks
SubTopic:
SwiftUI
I have an app which uses Scene
var body: some Scene {
WindowGroup {
RootView(root: appDelegate.root)
.edgesIgnoringSafeArea(.all)
.onOpenURL { url in
let stringUrl = url.absoluteString
if (stringUrl.starts(with: "http")) {
handleUniversalLink(url: stringUrl)
} else if (stringUrl.starts(with: "fb")) {
let _ = ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation])
}
}
}
}
I need to detect when a user taps on status bar. And call some functions when he does it. Is it possible in Swift?
Topic:
UI Frameworks
SubTopic:
SwiftUI
I'm wondering what the correct, or recommended, way is to dismiss a SwiftUI that is being presented as a sheet hosted by an NSHostingController. The usual technique of invoking @Environment(\.dismiss) does not appear to work.
Consider the code below. An NSWindowController is attempting to display a SwiftUI SettingsView as a sheet. The sheet is correctly presented, but the SettingsView is unable to dismiss itself.
I am able to make it work by passing a closure into SettingsView that calls back to the NSWindowController but it's rather convoluted because SettingsView doesn't know the view controller that's hosting it until after SettingsView has been created, which means "finding" that view controller in the window controller to dismiss is more involved than it should be.
Is there a better strategy to leverage here?
final class MyViewController: NSViewController {
@IBAction func buttonClicked(_ sender: NSButton) {
if let presenter = window?.contentViewController {
presenter.presentAsSheet(NSHostingController(rootView: SettingsView()))
}
}
}
struct SettingsView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack {
Button("Cancel", role: .cancel) {
dismiss() // This call does not dismiss the sheet.
} .keyboardShortcut(.cancelAction)
}
}
}
Thank you.
macOS 15.4.1 (24E263), Xcode 16.3 (16E140)
When I run my iOS app on a Mac using Mac Catalyst, several sharing options that show up on an iOS device in a share sheet are absent on the Mac. Clicking on Edit Extensions, I see Mail, Message and AirDrop, their switches are on and disabled. All three items show up when I share from Safari or Notes.
How can I make Mail, Message and AirDrop available?
For example, when sharing data, no share extensions are shown.
For text, only Simulator, Shortcuts and Copy are shown.
Is it not possible to dynamically change or constrain an NSPreferencePane's mainView size? I have looked all over and this doesn't seem to be mentioned anywhere. The most I can seemingly do is set the frame and hope the user doesn't resize the window.
class scor: NSPreferencePane {
override func mainViewDidLoad() {
mainView = NSHostingView(rootView: ContentView())
mainView.frame = NSMakeRect(0, 0, 668, 1048)
}
}
Here is a screenshot, just with a simple webview as a test, note the scrollbar:
My storyboard is just from the default prefpane Xcode template, nothing special. I looked at the header file for NSPreferencePane and came up with nothing. All I can think of is that this is impossible due to the way they are implemented? The only thing we seemingly have access to is mainView, so I can't like constrain the size of mainView to its parent, for example.
Additionally, if I make a new preference pane, and make a button or other view that I choose to resize to fill horizontally and vertically, it does that, but not really? Here is what that looks like:
The behaviour is similar to the previous preference pane, the width does adapt correctly, the height stays the same, forever.
Not that it really matters but I am using macOS 14.7.6 on an M2 air
Is it actually possible to display animation (even a simple one) on Live Activity? But on these cases:
The main app is terminated - of course, I know I can use the main app to keep updating the Live Activity to make simple animations work, but in this case, the main app is killed.
Live Activity data is not updating - I also understand that the Live Activity can perform animations when its data is being update via push notification or other means, but the current case is the data is not being updated.
I’ve tried several ways to achieve this, but nothing seems to work.
Just when I was about to give up, I found this video from Apple’s official channel:
https://www.youtube.com/watch?v=m6WMwSj_EbA
At 4:14 in this video, you can see the text "Locating Driver" with the breathing animation. Could someone please help me understand how to implement that kind of animation in a Live Activity when:
The main app is not running, and
The Live Activity data is not updating?
I have a DocumentGroup working with a FileDocument, and that's fine.
However, when someone creates a new document I want them to have to immediately save it. This is the behavior on ipadOS and iOS from what I can understand (you select where before the file is created).
There seems to be no way to do this on macOS?
I basically want to have someone:
create a new document
enter some basic data
hit "create" which saves the file
then lets the user start editing it
(1), (2), and (4) are done and fairly trivial.
(3) seems impossible, though...?
This really only needs to support macOS but any pointers would be appreciated.
Hi!
I am having issues with my internal testing app now showing up the same through different users devices?
I want to add the option to choose an alternative icon inside the app.
Is there a way to load an icon asset from within the app? I downloaded Apple’s alternative icon sample, which is supposed to show a list of icons to choose from, but even in the sample, it did not work.
So the current solution is to add every alternative icon along with another image asset of the same image to display to the user. This sounds like a waste of bytes.
Thank you in advance for any help.
Topic:
UI Frameworks
SubTopic:
General
I have received permission from Apple to access SensorKit data for my app. I have granted all necessary permissions, but no data is being retrieved.
The didCompleteFetch method is being called, but I’m unsure where to find event data like Device Usage and Ambient Light. Additionally, the didFetchResult method is never called.
Could anyone please assist me in resolving this issue? Any guidance or troubleshooting steps would be greatly appreciated.
import SensorKit
class ViewController: UIViewController, SRSensorReaderDelegate {
let store = SRSensorReader(sensor: .deviceUsageReport)
override func viewDidLoad() {
super.viewDidLoad()
requestSensorAuthorization()
}
func requestSensorAuthorization() {
var sensors: Set<SRSensor> = [
.accelerometer,
.deviceUsageReport,
.messagesUsageReport,
.visits,
.keyboardMetrics,
.phoneUsageReport,
.ambientLightSensor
]
if #available(iOS 16.4, *) {
sensors.insert(.mediaEvents)
}
SRSensorReader.requestAuthorization(sensors: sensors) { error in
if let error = error {
print("Authorization failed: \(error.localizedDescription)")
} else {
self.store.startRecording()
self.requestSensorData()
print("Authorization granted for requested sensors.")
}
}
}
func requestSensorData() {
let fromTime = SRAbsoluteTime.fromCFAbsoluteTime(_cf: Date().addingTimeInterval(-60 * 60).timeIntervalSinceReferenceDate)
let toTime = SRAbsoluteTime.fromCFAbsoluteTime(_cf: Date().timeIntervalSinceReferenceDate)
let request = SRFetchRequest()
request.from = fromTime
request.to = toTime
request.device = SRDevice.current
store.fetch(request)
store.delegate = self
}
func sensorReader(_ reader: SRSensorReader, didCompleteFetch fetchRequest: SRFetchRequest) {
print("Fetch request completed: \(fetchRequest.from) to \(fetchRequest.to)")
Task {
do {
let samples = try await reader.fetch(fetchRequest)
print("Samples count: \(samples)")
} catch {
print("Error Fetching Data: \(error.localizedDescription)")
}
}
}
func sensorReader(_ reader: SRSensorReader, fetching fetchRequest: SRFetchRequest, didFetchResult result: SRFetchResult<AnyObject>) -> Bool {
print(result)
return true
}
}
The behavior of the Button in ScrollView differs depending on how the View is displayed modally.
When the View is displayed as a .fullScreenCover, if the button is touched and scrolled without releasing the finger, the touch event is canceled and the action of the Button is not called.
On the other hand, if the View is displayed as a .sheet, the touch event is not canceled even if the view is scrolled without lifting the finger, and the action is called when the finger is released.
In order to prevent accidental interaction, I feel that the behavior of .fullScreenCover is better, as it cancels the event immediately when scrolling. Can I change the behavior of .sheet?
Demo movie is here:
https://x.com/kenmaz/status/1896498312737611891
Sample code
import SwiftUI
@main
struct SampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var showSheet = false
@State private var showFullScreen = false
var body: some View {
VStack(spacing: 16) {
Button("Sheet") {
showSheet.toggle()
}
Button("Full screen") {
showFullScreen.toggle()
}
}
.sheet(isPresented: $showSheet) {
SecondView()
}
.fullScreenCover(isPresented: $showFullScreen) {
SecondView()
}
.font(.title)
}
}
struct SecondView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
ScrollView {
Button("Dismiss") {
dismiss()
}
.buttonStyle(MyButtonStyle())
.padding(.top, 128)
.font(.title)
}
}
}
private struct MyButtonStyle: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration
.label
.foregroundStyle(.red)
.background(configuration.isPressed ? .gray : .clear)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI