Post

Replies

Boosts

Views

Activity

Context menus, alerts, popovers and tips do not respect preferred color scheme
It seems like some UI elements just don't use the preferred color scheme of their parent element: import SwiftUI struct ContentView: View { var body: some View { VStack { Button("Hold Me") { } .contextMenu(ContextMenu(menuItems: { Button("I should be dark") { } })) } .padding() .preferredColorScheme(.dark) } } If you set the device appearance to dark, then the context menu shows the correct color scheme. Setting .preferredColorScheme(.dark) to Button directly doesn't help. Aside from context menus, this applies to all sorts of elements: popovers, alerts, tips, ... Is there a workaround for this? Apple folks: FB13391355
0
0
655
Nov ’23
IAP rejected (Guideline 2.1) while binary waiting for review?
That's a new one for me. I have submitted 2 IAP along with an update for my app. The Mac binary was approved but then one of the IAP was rejected with this message: "We have returned your IAP product/s to you as the required binary was not submitted. When you are ready to submit the binary, please resubmit the IAPs with the binary." I'm not sure what this means as the related binary is actually waiting for review. What does this error means and how can I fix it?
0
0
657
Dec ’23
Transaction.currentEntitlements never returns if there are no entitlements?
I'm uncertain about the reason behind Transaction.currentEntitlements not returning nil when there are no current entitlements. The challenge I'm facing is that, in the scenario where a trial period concludes, Transaction.currentEntitlements seems to perpetually withhold any response, leaving me without a means to discern the conclusion of the trial. I'm puzzled as to why this method doesn't simply return nil when no entitlements are detected. It would be immensely helpful if someone could shed light on the rationale behind this behavior or point out any potential errors in my understanding. Your insights would be greatly appreciated. Thanks.
0
0
717
Dec ’23
Keyboard will not show when setting focus on a SwiftUI text field from a button in an ornament on visionOS
Using a button that is placed in the bottom ornament to set focus on a text field will not display the keyboard properly while a button embedded in the view will behave as expected. To demonstrate the issue, simply run the attached project on Vision Pro with visionOS 1.1 and tap the Toggle 2 button in the bottom ornament. You’ll see that the field does have focus but the keyboard is now visible. Run the same test with Toggle 1 and the field will get focus and the keyboard will show as expected. import SwiftUI import RealityKit import RealityKitContent struct ContentView: View { @State private var text = "" @State private var showKeyboard = false @FocusState private var focusedField: FocusField? private enum FocusField: Hashable { case username case password } var body: some View { VStack { TextField("Test", text: $text) .focused($focusedField, equals: .username) Text("Entered Text: \(text)") .padding() Button("Toggle 1") { // This button will work and show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } Spacer() } .padding() .toolbar { ToolbarItem(placement: .bottomOrnament) { Button("Toggle 2") { // This button will set focus properly but not show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } } } } } Is there a way to work around this? FB13641609
1
0
756
Jan ’25
onKeyPress not working on iOS/iPadOS 17.4 but fine on macOS
According to a post on hackingwithswift.com, this should work on iOS/iPadOS: import SwiftUI struct ContentView: View { @FocusState private var focused: Bool @State private var key = "" var body: some View { Text(key) .focusable() .focused($focused) .onKeyPress { press in key += press.characters return .handled } .onAppear { focused = true } } } It does not work for me using a hardware keyboard on an iPad running the latest iPadOS 17.4 beta but it does work on my Mac. FB13644182
1
0
862
Feb ’24
Search Ads (Basic) campaign stopped at previous budget even if it was raised during the month.
I raised the monthly budget for this app from $1300 to $2000 during July, but the campaign stopped once it reached $1303.84 around July 21st. I understand that lowering the budget should only apply in the following month, so why did the campaign stop even though there was roughly $700 left for the month? The issue is that the system spent the initial budget within three weeks as if it was using the new budget, so I don't have ads showing for the remainder of the month. The CPI is set at $5.60 per recommendation, and the average CPI is $1.28, so I don't think the issue is that the bid is not high enough.
1
0
634
Jul ’24
Glass effect on a stroke
I'm trying to apply a glass effect on a circle stroke but all it does is apply it to the circle itself and not the stroke: import SwiftUI let kCarouselCircleSize: CGFloat = 150 let kCarouselOpacity: Double = 0.3 let kCarouselStrokeWidth: CGFloat = 60 struct ContentView: View { @State var showing = false var body: some View { VStack(spacing: 60) { Text("ultraThinMaterial:") .font(.title) CarouseCircle(drawProgress: 0.7, isActive: false) Text("glassEffect()") .font(.title) CarouseCircle(useGlassEffect: true, drawProgress: 0.7, isActive: false) } .background(content: { Image(.background2) }) .padding() } } struct CarouseCircle: View { var size: CGFloat = kCarouselCircleSize var strokeWidth: CGFloat = kCarouselStrokeWidth var useGlassEffect: Bool = false var drawProgress: CGFloat var isActive: Bool var body: some View { if useGlassEffect { Circle() .trim(from: 0, to: drawProgress) .fill(.clear) .stroke(.blue, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round)) .frame(width: size, height: size) .glassEffect() .shadow(color: .black.opacity(kCarouselOpacity), radius: isActive ? 4 : 1, x: 0, y: 0) .rotationEffect(.degrees(-90)) // Start drawing at button 1's position } else { Circle() .trim(from: 0, to: drawProgress) .fill(.clear) .stroke(.ultraThinMaterial, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round)) .frame(width: size, height: size) .shadow(color: .black.opacity(kCarouselOpacity), radius: isActive ? 4 : 1, x: 0, y: 0) .rotationEffect(.degrees(-90)) // Start drawing at button 1's position } } } Here's the result: Is this supported, a bug or something I'm doing wrong?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
157
Jul ’25
Set filename to use for "Save to Files" with ShareLink?
Isn't there no way to set the default filename to use when we want to save a DataRepresentation to a file? If I export to JSON, the filename is "JSON.json" is used by iOS, even if I set the name to use in SharePreview. struct ContentView: View {     let car = Car(id: UUID(), name: "911", items:                     [Item(id: UUID(),date: .now, desc: "oil change"),                      Item(id: UUID(),date: .now, desc: "Battery")])     var body: some View {         VStack {             ShareLink(item: car, preview: SharePreview(car.name))         }         .padding()     } } extension UTType {     static var car: UTType = UTType(exportedAs: "com.acme.cararchive") } struct Car: Codable {     let id: UUID     let name: String     let items: [Item] } extension Car: Transferable {     static var transferRepresentation: some TransferRepresentation {         DataRepresentation(contentType: .json) { archive in             try JSONEncoder().encode(archive)         } importing: { data in             try JSONDecoder().decode(Car.self, from: data)         }     } } struct Item: Codable {     let id: UUID     let date: Date     let desc: String }
4
0
2.6k
Nov ’24
Placeholders for text fields embedded in forms (macOS)
It seems like there's no way to set a placeholder in a text field when it is in a form on macOS. This is not an issue on iOS. import SwiftUI struct ContentView: View { @State private var textUp = "" @State private var textDown = "" var body: some View { VStack { Form { Text("In a form:") .fontWeight(.bold) TextField("placeholder", text: $textUp) } Text("Not in a form:") .fontWeight(.bold) TextField("placeholder", text: $textDown) } .padding() } } Am I missing something or is this just not supported?
1
0
1.2k
Feb ’23
TableColumn with text and image
I'm trying to display a Label in a TableColumn but the header is not rendered properly: Here's some code: struct Computer: Identifiable { let id: UUID let name: String init(_ name: String) { id = UUID() self.name = name } } struct ContentView: View { private var computers = [Computer("iMac"), Computer("MacBook"), Computer("Mac mini")] @State private var selectedComputers = Set<Computer.ID>() @State private var sortOrder = [KeyPathComparator(\Computer.name)] var body: some View { Table(computers, selection: $selectedComputers, sortOrder: $sortOrder) { // Header rendered incorrectly TableColumn("Name", value: \.name) { computer in Label(computer.name, systemImage: "desktopcomputer") } // This works: // TableColumn("Name", value: \.name) } } } If I use a Text element instead (or not define any custom view for the TableColumn), the header is rendered properly: Am I doing it wrong or this is a bug?
1
0
1.2k
Feb ’23
NSCocoaErrorDomain 4097: connection to service named com.apple.storekitagent
We had a few users reporting this issue where our app is unable to connect to StoreKit. Failed product request from the App Store server: systemError(Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named com.apple.storekitagent" UserInfo={NSDebugDescription=connection to service named com.apple.storekitagent}) This occurs when calling Product.products(for:). Some users mentioned they had to restart their Mac in safe mode to make the error go away, some had DNS cache issues and clearing those helped, or some found the culprit to be Adguard. What could be causing this error as it is not very clear what's causing it?
4
0
3.5k
Feb ’24
Toolbar buttons disappearing when showing a navigation split view as a sheet
When displaying a view using a navigation Split View as a sheet, the toolbar button will disappear if you leave the app and resume it. import SwiftUI struct Folder: Hashable, Identifiable { let id = UUID() let name: String } struct ContentView: View { @State private var showingSettings = false var body: some View { VStack { Button { showingSettings.toggle() } label: { Text("Settings") } } .sheet(isPresented: $showingSettings, content: { SettingsView() }) .padding() } } struct SettingsView: View { @Environment(\.dismiss) private var dismiss @State private var selectedFolder: Folder? = nil private var folders = [Folder(name: "Recents"), Folder(name: "Deleted"), Folder(name: "Custom")] var body: some View { NavigationSplitView { SidebarView(selectedFolder: $selectedFolder, folders: folders) } detail: { VStack { if let folder = selectedFolder { Text(folder.name) } else { Text("No selection") } } .toolbar { ToolbarItem(placement: .cancellationAction) { Button { dismiss() } label: { Text("Cancel") } } ToolbarItem(placement: .confirmationAction) { Button { dismiss() } label: { Text("Save") } } } } } } struct SidebarView: View { @Binding var selectedFolder: Folder? var folders: [Folder] var body: some View { List(selection: $selectedFolder) { ForEach(folders) { folder in NavigationLink(value: folder) { Text(folder.name) } } } } } Steps to reproduce the issue: Launch the attached project on an iPad or iPad simulator Tap the Settings button Select one item in the sidebar Use the app switcher to open an other app or just leave the app Bring back the app Result: Both Cancel and Save buttons are gone. Note: This will not occur if no item is selected in the sidebar. FB12991687
4
0
1.9k
Jul ’24