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
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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
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.
Hi everyone,
I’m running into a strange animation glitch when using a Menu inside a glassEffect container.
Here’s a minimal example:
import SwiftUI
struct ContentView: View {
@Namespace private var namespace
var body: some View {
ZStack {
Image(.background)
.resizable()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.ignoresSafeArea()
GlassEffectContainer {
HStack {
Button("b1") {}
Button("b2") {}
Button("b3") {}
Button("b4") {}
Button("b5") {}
Menu {
Button("t1") { }
Button("t2") { }
Button("t3") { }
Button("t4") { }
Button("t5") { }
} label: {
Text("Menu")
}
}
}
.padding(.horizontal)
.frame(height: 50)
.glassEffect()
}
}
}
What happens:
The bar looks fine initially:
When you open the Menu, the entire bar morphs into the menu:
When dismissing, the bar briefly animates into a solid rectangle before reapplying the glass effect:
Questions:
Is there a way to prevent that brief rectangle animation when dismissing the menu?
If not, is it possible to avoid the morphing altogether and have the menu simply overlay on top of the bar instead of replacing it?
Any ideas or workarounds would be greatly appreciated!
This code works fine on macOS 11:
var body: some View {
VStack {
ActionControl()
.padding()
.onDrag { () -> NSItemProvider in
let value = Action(string: "hello, world").string
let p = ActionProfile(value: value)
return NSItemProvider(item: p, typeIdentifier: ActionProfile.pasteboardType)
}
MyTextView()
.padding()
}
}
class ActionProfile: NSObject, NSCoding, NSSecureCoding {
static var supportsSecureCoding: Bool = true
static var pasteboardType = "com.my.app.action.profile"
@objc var rawValue: String
func encode(with aCoder: NSCoder) {
aCoder.encode(rawValue, forKey: "value")
}
required init(value: String) {
self.rawValue = value
}
required init?(coder aDecoder: NSCoder) {
self.rawValue = aDecoder.decodeObject(of: NSString.self, forKey: "value")! as String
}
required init?(pasteboardPropertyList propertyList: Any, ofType type: NSPasteboard.PasteboardType) {
return nil
}
}
extension ActionProfile: NSPasteboardWriting, NSPasteboardReading {
static var nsPasteboardType: NSPasteboard.PasteboardType = .init(pasteboardType)
static func readingOptions(forType type: NSPasteboard.PasteboardType, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions {
return .asKeyedArchive
}
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
if type == ActionProfile.nsPasteboardType {
return try! NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
}
return nil
}
static func readableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
}
extension MyTextViewControl {
override internal var writablePasteboardTypes: [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType] + super.writablePasteboardTypes
}
override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool {
return true
}
override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation {
let location = self.characterIndexForInsertion(at: self.convert(sender.draggingLocation, from: nil))
self.setSelectedRange(NSRange(location: location, length: 0))
return sender.draggingSource is MyTextViewControl ? .move : .copy
}
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
let pboard = sender.draggingPasteboard
if pboard.availableType(from: [ActionProfile.nsPasteboardType]) == ActionProfile.nsPasteboardType {
if let profiles = pboard.readObjects(forClasses: [ActionProfile.self], options: nil) as? [ActionProfile], !profiles.isEmpty {
let alert = NSAlert()
alert.messageText = "WORKS"
alert.runModal()
return true
}
else {
let alert = NSAlert()
alert.messageText = "FAILED"
alert.runModal()
return super.performDragOperation(sender)
}
}
return super.performDragOperation(sender)
}
}
On macOS 12 beta, when calling pboard.readObjects(...) I get this error when trying to drag the item into a NSTextView:
Failed to initialize keyed unarchiver for pasteboard data: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?}
I've noticed that encode(with aCoder: NSCoder) isn't called at all on macOS 12 but is on macOS 11.
Are there any changes in macOS 12 regarding NSCoding or NSSecureCoding or is this just a bug?
Why won't a button using a Label show in the keyboard shortcuts list (holding ⌘ key)?
struct ContentView: View {
var body: some View {
NavigationSplitView {
SidebarView()
} detail: {
Text("Hello, world")
}
}
}
struct SidebarView: View {
let items = [1, 2, 3, 4, 5, 6]
var body: some View {
List(items, id:\.self) { item in
Text("\(item)")
}
.toolbar {
Button {
// Do something
} label: {
Label("New", systemImage: "plus")
}
.keyboardShortcut("n") // Will NOT show in shortcuts list
Button("Play") {
// Do something
}
.keyboardShortcut("p") // Will show in shortcuts list
}
}
}
Am I doing something wrong or is this just yet another SwiftUI shortcoming?
I don't know if this is a bug but when you put text fiels in a form, pressing the Tab key on a physical keyboard will just jump to the first field and stay there:
import SwiftUI
struct ContentView: View {
enum FocusedField {
case firstName, lastName
}
@State var name = ""
@State var lastName = ""
@FocusState private var focusedField: FocusedField?
var body: some View {
Form {
TextField("Name", text: $name)
.focused($focusedField, equals: .firstName)
TextField("Last", text: $lastName)
.focused($focusedField, equals: .lastName)
}
.padding()
.onAppear {
focusedField = .firstName
}
}
}
This is the result:
Note that this works fine on macOS or when using the Tab key on the virtual keyboard.
If you put the fields into a VStack instead, you'll be able to move through the fields via the Tab key.
Is .refreshable supposed to do anything on macOS? Works fine on iOS and iPadOS but it's not triggered on macOS. It's available since macOS 12 but the documentation doesn't mention anything about that.
https://developer.apple.com/documentation/swiftui/view/refreshable(action:)
Somehow the Swift compiler is unable to this code:
@Observable class ServiceBrowser: NSObject {
typealias ResolveServiceCompletionBlock = (Bool, Error?) -> Void
fileprivate var resolveServiceCompletionHandler: ResolveServiceCompletionBlock? = nil
}
Here's the crash:
4 . While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/luc/Work/Repositories/app-shared/App/Shared/Connectivity/ServiceBrowser.swift")
5 . While silgen init accessor SIL function "@$s7App14ServiceBrowserC07resolveB17CompletionHandler33_5B15C352D9CC926D1F8A0ECAC5970199LLySb_s5Error_pSgtcSgvi".
for init for resolveServiceCompletionHandler (at /Users/luc/Work/Repositories/ap-shared/App/Shared/Connectivity/ServiceBrowser.swift:86:21)
6 . While emitting reabstraction thunk in SIL function "@$sSbs5Error_pSgIegyg_ytIegd_TR".
How come keyboard shortcuts associated to toolbar items do not show up when you hold down the command key?
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button {
} label: {
Text("Tap Me!")
}
.keyboardShortcut("o", modifiers: .command)
}
.padding()
.toolbar {
ToolbarItem {
Button {
} label: {
Image(systemName: "bolt")
}
.keyboardShortcut("k", modifiers: .command)
}
}
}
}
}
See screenshot. The shortcut for "Tap Me!" is being shown but not the one for the toolbar item. Am I doing something wrong or this is just not supported yet in SwiftUI? If that's the case, that seems to be a significant omission.
I've spent 3 days moving localization from my older project to my new project and converted to Strings Catalog.
When I tried to export, I got the Unable to build project for localization string extraction error.
Read about that and the workaround seems to be to set Localisation Export Supported to NO, which I did.
I worked once and now it refuses to export and complains about missing targets, which I had to remove from the export process as recommended. WTH?
Or, at some point it complained about a missing Swift Package.
wwdc2023-10155
Trying to debug StoreKit on device using a sandboxed user. When I want to show manageSubscriptionsSheet, the screen flashes but nothing shows.
This is visible in the console:
SKEngagementRemoteViewTask: Presenting system engagement request. Request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 }
Present engagement request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 }, clientBundleID: com.acme.myapp
Finished presenting engagement request with view service
There isn't much information in the documentation so I'm not sure if it's me not doing things correctly or a bug in iOS 17.2?
It appears there's an issue with the Mac App Store's ability to process offer codes, unlike its iOS counterpart, which handles them seamlessly. Users attempting to redeem a code on their Mac are encountering a "Cannot redeem code. Try another code" error.
Considering the Mac App Store's long history, having been introduced nearly 13 years ago, it's high time for it to align with the iOS App Store's functionality. While it's close to 80% there, addressing these lingering issues would greatly improve the user experience.
FB13463658
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store
App Store Connect
Mac App Store
I found this 3-year old thread but at that time, linking transactions was not supported:
https://developer.apple.com/forums/thread/650622?page=1#774420022
Essentially, I want to be able to get information about the transaction made by the purchaser but with a transaction that has ownershipType set to familyShared.
Is this possible at the moment?
I'm unable to figure out how to know when my app no longer has focus. ScenePhase will only change when the WindowGroup gets created or closed.
UIApplication.didBecomeActive and UIApplication.didEnterBackgroundNotification are not called either when say you move focus to Safari.
What's the trick?