Post

Replies

Boosts

Views

Activity

Reply to Problems with AVAudioPlayerNode's scheduleBuffer function
I also ran into this issue. My problem was that I was using an offset on inputNode.lastRenderTime. To resolve it, I needed to convert it using inputNode.playerTime(forNodeTime: inputNode.lastRenderTime) before I schedule with scheduleBuffer(buffer, at: futureTime) See here https://developer.apple.com/documentation/avfaudio/avaudioplayernode/1390449-playertime
Topic: Media Technologies SubTopic: Audio Tags:
Oct ’23
Reply to .sheet no longer dismissable in WatchOS 7?
The fix is actually much simpler (at least for me running watchOS 10). If you embed your sheet view in a navigation stack like this, there will be a little circular "X" button at the top left of your sheet. MyMainView() .sheet { NavigationStack { MySheetView() } } As it turns out, the default cancel button is embedded in the toolbar, and the toolbar doesn't show up at all unless your view is embedded in a navigation stack
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to In SwiftUI on macOS, how to make a scroll wheel scroll horizontally?
Fixed here: import AppKit struct CaptureVerticalScrollWheelModifier: ViewModifier { func body(content: Content) -> some View { content .background(ScrollWheelHandlerView()) } struct ScrollWheelHandlerView: NSViewRepresentable { func makeNSView(context: Context) -> NSView { let view = ScrollWheelReceivingView() return view } func updateNSView(_ nsView: NSView, context: Context) {} } class ScrollWheelReceivingView: NSView { private var scrollVelocity: CGFloat = 0 private var decelerationTimer: Timer? override var acceptsFirstResponder: Bool { true } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() window?.makeFirstResponder(self) } override func scrollWheel(with event: NSEvent) { var scrollDist = event.deltaX var scrollDelta = event.scrollingDeltaX if abs(scrollDist) < abs(event.deltaY) { scrollDist = event.deltaY scrollDelta = event.scrollingDeltaY } if event.phase == .began || event.phase == .changed || event.phase.rawValue == 0 { // Directly handle scrolling handleScroll(with: scrollDist, precise: event.hasPreciseScrollingDeltas) scrollVelocity = scrollDelta } else if event.phase == .ended { // Begin decelerating decelerationTimer = Timer.scheduledTimer(withTimeInterval: 0.016, repeats: true) { [weak self] timer in guard let self = self else { timer.invalidate(); return } self.decelerateScroll() } } else if event.momentumPhase == .ended { // Invalidate the timer if momentum scrolling has ended decelerationTimer?.invalidate() decelerationTimer = nil } } private func handleScroll(with delta: CGFloat, precise: Bool) { var scrollDist = delta if !precise { scrollDist *= 2 } guard let scrollView = self.enclosingScrollView else { return } let contentView = scrollView.contentView let contentSize = contentView.documentRect.size let scrollViewSize = scrollView.bounds.size let currentPoint = contentView.bounds.origin var newX = currentPoint.x - scrollDist // Calculate the maximum allowable X position (right edge of content) let maxX = contentSize.width - scrollViewSize.width // Ensure newX does not exceed the bounds newX = max(newX, 0) // No less than 0 (left edge) newX = min(newX, maxX) // No more than maxX (right edge) // Scroll to the new X position if it's within the bounds scrollView.contentView.scroll(to: NSPoint(x: newX, y: currentPoint.y)) scrollView.reflectScrolledClipView(scrollView.contentView) } private func decelerateScroll() { if abs(scrollVelocity) < 0.8 { decelerationTimer?.invalidate() decelerationTimer = nil return } handleScroll(with: scrollVelocity, precise: true) scrollVelocity *= 0.95 } } } extension View { func captureVerticalScrollWheel() -> some View { self.modifier(CaptureVerticalScrollWheelModifier()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to NWParemeters.requiredLocalEndpoint is ignored in VisionOS
Unfortunately I don't have a real device to confirm and won't have the funds to get one anytime soon, but your asking did make me recheck and I found some interesting behavior. Working on iOS Real Device iPad, iPhone (Uses port 6970) Working on macOS Real Device (Uses port 6970) Not working on iOS Simulator (Uses random port) Not working on VisionOS Simulator (Uses random port) I thought I had already checked and it worked on iOS simulator, but I guess I mis-remembered. I'll consider this closed for now until I get a VisionOS bug report saying that it's an issue there on real devices.
Mar ’24
Reply to No Devices Registered Error tvOS
This response is incorrect. Currently there isn't a way to publish an tvOS app to the App Store or even archive the app without owning an Apple TV. You can however build and test your application on the simulator without owning an Apple TV. Interestingly enough, this isn't a requirement with visionOS as of now (and hopefully, fingers crossed it won't be added).
Mar ’24
Reply to In SwiftUI on macOS, how to make a scroll wheel scroll horizontally?
Actually I fixed it better here: import AppKit import SwiftUI struct CaptureVerticalScrollWheelModifier: ViewModifier { func body(content: Content) -> some View { content .background(ScrollWheelHandlerView()) } struct ScrollWheelHandlerView: NSViewRepresentable { func makeNSView(context _: Context) -> NSView { let view = ScrollWheelReceivingView() return view } func updateNSView(_: NSView, context _: Context) {} } class ScrollWheelReceivingView: NSView { private var scrollVelocity: CGFloat = 0 private var decelerationTimer: Timer? override var acceptsFirstResponder: Bool { true } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() window?.makeFirstResponder(self) } // Don't capture vertical scroll for precise scrolling (e.g. magic mouse/trackpad), and don't capture if we are already scrolling horizontally (e.g. shift + scroll). If we don't do this, we get very unpredictable behavior override func scrollWheel(with event: NSEvent) { if event.hasPreciseScrollingDeltas || abs(event.scrollingDeltaX) > 0.000001 || abs(event.deltaX) > 0.000001 { super.scrollWheel(with: event) return } if let cgEvent = event.cgEvent?.copy() { cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis2, value: Double(event.scrollingDeltaY / 10)) cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis1, value: Double(0)) cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis3, value: Double(0)) cgEvent.setDoubleValueField(.mouseEventDeltaX, value: Double(0)) cgEvent.setDoubleValueField(.mouseEventDeltaY, value: Double(0)) // Once we flip the scrolling axis to X and set the rest to 0, we can just send the event the same as before. All the deceleration and such will get handled natively by the system! if let nsEvent = NSEvent(cgEvent: cgEvent) { super.scrollWheel(with: nsEvent) } else { super.scrollWheel(with: event) } } else { super.scrollWheel(with: event) } } } } extension View { func captureVerticalScrollWheel() -> some View { modifier(CaptureVerticalScrollWheelModifier()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’25
Reply to Unrelated 3rd party apps interfering with NWConnectionGroup's state
Is there any way I can check the status of this bug? Has this been resolved in iOS 17?
Replies
Boosts
Views
Activity
Oct ’23
Reply to Unrelated 3rd party apps interfering with NWConnectionGroup's state
For posterity, I implemented similar code to the above on macOS Sonoma 14.0 (23A344) and got the same address already in use error :/
Replies
Boosts
Views
Activity
Oct ’23
Reply to Problems with AVAudioPlayerNode's scheduleBuffer function
I also ran into this issue. My problem was that I was using an offset on inputNode.lastRenderTime. To resolve it, I needed to convert it using inputNode.playerTime(forNodeTime: inputNode.lastRenderTime) before I schedule with scheduleBuffer(buffer, at: futureTime) See here https://developer.apple.com/documentation/avfaudio/avaudioplayernode/1390449-playertime
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to .sheet no longer dismissable in WatchOS 7?
The fix is actually much simpler (at least for me running watchOS 10). If you embed your sheet view in a navigation stack like this, there will be a little circular "X" button at the top left of your sheet. MyMainView() .sheet { NavigationStack { MySheetView() } } As it turns out, the default cancel button is embedded in the toolbar, and the toolbar doesn't show up at all unless your view is embedded in a navigation stack
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to In SwiftUI on macOS, how to make a scroll wheel scroll horizontally?
Fixed here: import AppKit struct CaptureVerticalScrollWheelModifier: ViewModifier { func body(content: Content) -> some View { content .background(ScrollWheelHandlerView()) } struct ScrollWheelHandlerView: NSViewRepresentable { func makeNSView(context: Context) -> NSView { let view = ScrollWheelReceivingView() return view } func updateNSView(_ nsView: NSView, context: Context) {} } class ScrollWheelReceivingView: NSView { private var scrollVelocity: CGFloat = 0 private var decelerationTimer: Timer? override var acceptsFirstResponder: Bool { true } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() window?.makeFirstResponder(self) } override func scrollWheel(with event: NSEvent) { var scrollDist = event.deltaX var scrollDelta = event.scrollingDeltaX if abs(scrollDist) < abs(event.deltaY) { scrollDist = event.deltaY scrollDelta = event.scrollingDeltaY } if event.phase == .began || event.phase == .changed || event.phase.rawValue == 0 { // Directly handle scrolling handleScroll(with: scrollDist, precise: event.hasPreciseScrollingDeltas) scrollVelocity = scrollDelta } else if event.phase == .ended { // Begin decelerating decelerationTimer = Timer.scheduledTimer(withTimeInterval: 0.016, repeats: true) { [weak self] timer in guard let self = self else { timer.invalidate(); return } self.decelerateScroll() } } else if event.momentumPhase == .ended { // Invalidate the timer if momentum scrolling has ended decelerationTimer?.invalidate() decelerationTimer = nil } } private func handleScroll(with delta: CGFloat, precise: Bool) { var scrollDist = delta if !precise { scrollDist *= 2 } guard let scrollView = self.enclosingScrollView else { return } let contentView = scrollView.contentView let contentSize = contentView.documentRect.size let scrollViewSize = scrollView.bounds.size let currentPoint = contentView.bounds.origin var newX = currentPoint.x - scrollDist // Calculate the maximum allowable X position (right edge of content) let maxX = contentSize.width - scrollViewSize.width // Ensure newX does not exceed the bounds newX = max(newX, 0) // No less than 0 (left edge) newX = min(newX, maxX) // No more than maxX (right edge) // Scroll to the new X position if it's within the bounds scrollView.contentView.scroll(to: NSPoint(x: newX, y: currentPoint.y)) scrollView.reflectScrolledClipView(scrollView.contentView) } private func decelerateScroll() { if abs(scrollVelocity) < 0.8 { decelerationTimer?.invalidate() decelerationTimer = nil return } handleScroll(with: scrollVelocity, precise: true) scrollVelocity *= 0.95 } } } extension View { func captureVerticalScrollWheel() -> some View { self.modifier(CaptureVerticalScrollWheelModifier()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to NWParemeters.requiredLocalEndpoint is ignored in VisionOS
Unfortunately I don't have a real device to confirm and won't have the funds to get one anytime soon, but your asking did make me recheck and I found some interesting behavior. Working on iOS Real Device iPad, iPhone (Uses port 6970) Working on macOS Real Device (Uses port 6970) Not working on iOS Simulator (Uses random port) Not working on VisionOS Simulator (Uses random port) I thought I had already checked and it worked on iOS simulator, but I guess I mis-remembered. I'll consider this closed for now until I get a VisionOS bug report saying that it's an issue there on real devices.
Replies
Boosts
Views
Activity
Mar ’24
Reply to NWParemeters.requiredLocalEndpoint is ignored in VisionOS
Submitted as FB13686829
Replies
Boosts
Views
Activity
Mar ’24
Reply to No Devices Registered Error tvOS
This response is incorrect. Currently there isn't a way to publish an tvOS app to the App Store or even archive the app without owning an Apple TV. You can however build and test your application on the simulator without owning an Apple TV. Interestingly enough, this isn't a requirement with visionOS as of now (and hopefully, fingers crossed it won't be added).
Replies
Boosts
Views
Activity
Mar ’24
Reply to Xcode 15.3 AppIntentsSSUTraining warning: missing the definition of locale # variables.1.definitions
I'm seeing it in XCode 16 beta as well.
Topic: Machine Learning & AI SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’24
Reply to In SwiftUI on macOS, how to make a scroll wheel scroll horizontally?
Actually I fixed it better here: import AppKit import SwiftUI struct CaptureVerticalScrollWheelModifier: ViewModifier { func body(content: Content) -> some View { content .background(ScrollWheelHandlerView()) } struct ScrollWheelHandlerView: NSViewRepresentable { func makeNSView(context _: Context) -> NSView { let view = ScrollWheelReceivingView() return view } func updateNSView(_: NSView, context _: Context) {} } class ScrollWheelReceivingView: NSView { private var scrollVelocity: CGFloat = 0 private var decelerationTimer: Timer? override var acceptsFirstResponder: Bool { true } override func viewDidMoveToWindow() { super.viewDidMoveToWindow() window?.makeFirstResponder(self) } // Don't capture vertical scroll for precise scrolling (e.g. magic mouse/trackpad), and don't capture if we are already scrolling horizontally (e.g. shift + scroll). If we don't do this, we get very unpredictable behavior override func scrollWheel(with event: NSEvent) { if event.hasPreciseScrollingDeltas || abs(event.scrollingDeltaX) > 0.000001 || abs(event.deltaX) > 0.000001 { super.scrollWheel(with: event) return } if let cgEvent = event.cgEvent?.copy() { cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis2, value: Double(event.scrollingDeltaY / 10)) cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis1, value: Double(0)) cgEvent.setDoubleValueField(.scrollWheelEventDeltaAxis3, value: Double(0)) cgEvent.setDoubleValueField(.mouseEventDeltaX, value: Double(0)) cgEvent.setDoubleValueField(.mouseEventDeltaY, value: Double(0)) // Once we flip the scrolling axis to X and set the rest to 0, we can just send the event the same as before. All the deceleration and such will get handled natively by the system! if let nsEvent = NSEvent(cgEvent: cgEvent) { super.scrollWheel(with: nsEvent) } else { super.scrollWheel(with: event) } } else { super.scrollWheel(with: event) } } } } extension View { func captureVerticalScrollWheel() -> some View { modifier(CaptureVerticalScrollWheelModifier()) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’25
Reply to Writing an `NWProtocolFramerImplementation` to run on top of `NWProtocolWebSocket`
I ended up writing my own NWProtocolFramerImplementation re-implementing the necessary pieces of the websockets protocol here. I won't close here yet though in hope that someone can provide a better direction to others.
Replies
Boosts
Views
Activity
Jan ’25
Reply to AVAudioEngine Voice Processing Fails with Mismatched Input/Output Devices: AggregateDevice Channel Count Mismatch
Same issue for me
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
Mar ’25
Reply to Unable to launch + Attach to Mac Widget (Sonoma + Xcode 15)
Experiencing the same problem with the latest macos 15 still today (I have confirmed the binary actually does have the get-task-allow entitlement)
Replies
Boosts
Views
Activity
May ’25
Reply to Indicate Packet Loss With AVAudioConverter for OPUS Decoding
Also seeing this :(
Topic: Media Technologies SubTopic: Audio Tags:
Replies
Boosts
Views
Activity
May ’25