Dive into the world of programming languages used for app development.

All subtopics
Posts under Programming Languages topic

Post

Replies

Boosts

Views

Created

Using Observations with SwiftData @Model
I want to use the Observations AsyncSequence on some SwiftData @Model instances to determine if internal calculations need to be done. When a simple property is linked to the Observations it fires CONTINUOUSLY even though no change is made to the model property. Also, when I try to observe a property which is a list of another @Model type the Observations sequence does not fire when I add or remove items. I am hoping to use the async-algorithm's merge function so all the associated sequences can be combined since if any of the associated events should fire the calculation event.
4
0
2.8k
Jan ’26
JavaScript/Swift Interoperability
I think that it would be helpful to have better interoperability between Swift and JavaScript. There are a lot of useful packages on NPM that don't have equivalents for Swift. It would be helpful if Apple provided easier ways to use NPM packages in a Swift project. Currently, the JavaScriptCore framework is missing many standard things used in many packages, like the fetch API. It would be helpful to be able to run sandboxed JavaScript code inside of a Swift app but allow access to specific domains, folders, etc., using a permissions system similar to Deno.
6
1
3.3k
Jan ’26
vDSP.DiscreteFourierTransform failed to initialize with 5 * 5 * 2^n count
I am implementing the FFT using vDSP.DiscreteFourierTransform. According to the official documentation, the count parameter has requirements as outlined below: /// The `count` parameter must be: /// * For split-complex real-to-complex: `2ⁿ` or `f * 2ⁿ`, where `f` is `3`, `5`, or `15` and `n >= 4`. /// * For split-complex complex-to-complex: `2ⁿ` or `f * 2ⁿ`, where `f` is `3`, `5`, or `15` and `n >= 3`. /// * For interleaved: `f * 2ⁿ`, where `f` is `2`, `3`, `5`, `3x3`, `3x5`, or `5x5`, and `n>=2`. Despite adhering to these specifications in theory, my attempt to initialize an interleaved DFT with count = 2 * 2 * 5 * 5 (equivalent to 5×5 × 2²) resulted in a failure. Below is the code snippet I used for the initialization: do { let dft = try vDSP.DiscreteFourierTransform( previous: nil, count: 2 * 2 * 5 * 5, direction: .forward, transformType: .complexReal, ofType: DSPComplex.self ) print(dft) } catch { print("DFT init failed:", error) } Could somebody more knowledgeable with these APIs have a look? Thanks!
1
0
694
Jan ’26
iOS and Android
I currently have a iOS app live on the App Store but I also want to release it on Android, the whole code is in Swift so would that be possible or would I have to rewrite my whole apps code in a different coding language.
2
0
2.8k
Jan ’26
init?(coder: NSCoder) or init?(coder: (NSCoder?))
In this code, I use in some places required init?(coder: (NSCoder?)) { // Init some properties super.init(coder: coder!) } And in other places required init?(coder: NSCoder) { super.init(coder: coder) // Init some properties } Both seem to work. Is there a preferred one ? In which cases ? Or should I always use the second one ? And can super be called at anytime ?
2
0
674
Feb ’26
Calling a Objc method directly from C
I would like to avoid the middle man and call Objective C directly from C Currently I do this This is called from a dispatch table in a pure C file _ctx->mt_render_funcs.mtlEnd(_ctx); Which calls this routine in a obj c file .m void mtlEnd(MTRenderContext mt_ctx) { // Call the Objective-C method using Objective-C syntax [(__bridge id) mt_ctx->mt_render_funcs.mtlObj mtlEnd]; } Which ends up here... in ObjC #pragma mark mtlEnd (void)mtlEnd { // vertex buffer size_t size; size = sizeof(Vertex4ColorNormalTex) * _ctx->vert_eng.current_vertex; [_currentRenderEncoder setVertexBytes:_ctx->vert_eng.vertices length: size atIndex: VertexInputIndexVertices]; [_currentRenderEncoder drawPrimitives:(MTLPrimitiveType)_ctx->vert_eng.prim_type vertexStart:0 vertexCount:_ctx->vert_eng.current_vertex]; } It would simplify this to get rid of one call and call ObjC directly. The other idea is I want to use GCD and put a lock / unlock on the call from C to ensure thread safety so I can use GCD to dispatch a thread to do the ObjC routines. I want to stick with C as the foundation so it can be used directly from C or a FFI interface from other languages. But Metal works well in ObjC and I would prefer to use that. Thanks ahead of time.
3
0
1.2k
Feb ’26
Bridging Header doesn't seem to include my Swift class
I think have done everything by the book. I added a small Swift file to my Objective-C project. This is code in the project, not in a framework, so I did not use the public keyword: import Foundation @objc TestClass: NSObject { @objc init(){} } Adding this file prompted creating a bridging header and it should have added TestClass into it. I added the import to the Objective-C .m file. This didn't produce an error so the file must be there: #import "SoftServePro-Bridging-Header.h" I made a property for an instance of the class in the .h file: @property(nonatomic,strong) TestClass *test; I cleaned the project and did one compile for the precompiler to populate the bridging header. I have set Defines Module to Yes in Build Settings -> Packaging. I added a line in the .m code to create a TestClass: self.test=[[TestClass alloc]init]; And for my trouble I get the error message Now, this looks to me like TestClass is not in my bridging header because if it were it should know exactly what TestClass is, not just consider it a forward declaration. I haven't figured out any way to look at the actual contents of the bridging header after precompile, so I don't know if TestClass is there or not. The ONLY thing that I have not followed is that the documentation I have read says to put the bridging header in the same folder as the .xcodeproj file, but Xcode put it in with all the source code files (one folder down) and who am I to argue with Xcode??
3
0
1.3k
Mar ’26
Data Disappeared
Hi, writing a database app for storing equipment details. Spent the day doing minor changes and tidying with many backups made, and always re-building to check its all working. Everything ok but then next build looses all data, what's the best thing to check to see if the data is still there, any help would be fantastic.
1
0
1.2k
Mar ’26
Apple Silicon calling printf
What is the proper way to pass arguments to printf with multiple variables using ARM64 Apple Silicon? Example: fOutputStr: .asciz "Element[%d] = %d\n" // formated output string for an output of: Element[4] = 9 This code (see below) works on Raspberry Pi 5, on my Mac Studio, I am getting this output, Element[9] = 1871655168 What do I need to do to use printf from an assembly language call with multiple variables? I am using the following code. ` .align 2 // memory alignment model for 64-bit ARMc #if defined(APPLE) .global _main // Provide program starting address to linker Mac OS _main: #else .global main // Raspian and Linux main: #endif // stack frame work setup START stp x29, x30, [sp, -16]! str x20, [sp, -16]! mov x29, sp // stack frame work setup END // setup printf call #if defined(APPLE) adrp x0, fOutputStr@PAGE add x0, x0, fOutputStr@PAGEOFF #else ldr x0, =fOutputStr #endif mov w1, #4 mov w2, #9 print_brk: #if defined(APPLE) stp X0, X1, [SP, #-16]! stp X2, X3, [SP, #-16]! bl _printf ldp X2, X3, [SP], #16 ldp X0, X1, [SP], #16 #else bl printf #endif done: // closing stack frame work ldr x20, [sp],16 ldp x29, x30, [sp],16 // exit mov w0, wzr ret .data .align 4 // intArrayPtr: .word 3,7,5,2,4,8 // word, each value is offset by 4 fOutputStr: .asciz "Element[%d] = %d\n" // formated output string
6
1
766
4w
Why is the Documentation full of Conundrums?
I'm trying to learn and focus on the task and your examples keep having hidden conundrums in them. Here is an example that got me snagged for hours last night going, Well what the F do they want me to name it? What is it you want me to learn here? Because you pose a giant riddle of name something that you should be given a name for... My friend said to me that this is a common thing you will have to do and they were right however... What are you asking me to do? Get stuck on the variable naming problem where I'm going... Yeah those are math terms from 20+ years ago and I have no idea how to classify those terms... Are you asking me that? No. So why is that in the problem. These conundrums mixed in with legitimate problems honestly make me not want to learn Swift at all.
3
0
310
3w
Attached macro loses generated source file
I’m seeing what looks like a compiler / macro-expansion / build-pipeline issue. Environment: Xcode 26.4 RC (17E192, latest); I believe it is also reproducible on earlier versions. github source code I reduced this to a very small macOS/iOS app plus a local macro package. The app logic is trivial, but app exits immediately on launch with code 138 Important observations: If I inline everything into a single file, the problem disappears. I also see an error like this during investigation: The file path does not exist on the file system: /var/folders/.../swift-generated-sources/@__swiftmacro_18MacroFeedbackRepro20MountActivationState17PreservedRawValuefMm_.swift That makes me suspect this is not an application logic issue, but something in macro expansion / generated source handling / compiler pipeline.
2
0
1.8k
3w
On iPad with Swift Playgrounds: How to open chapter as a playground?
Note On a Mac with Xcode installed, or on an iPad with Swift Playgrounds, you can open this chapter as a playground. Playgrounds allow you to edit the code listings and see the results immediately. (Note in page 3) (I would like to open the chapter or book: Swift Programming Language in Swift Playground on iPad) https://books.apple.com/ve/book/the-swift-programming-language-swift-5-7-beta/id1002622538?l=en-GB Best regards
2
0
1k
3w
tvOS: Background audio + local caching works on Simulator but stops on real Apple TV device
Description: I’m developing a tvOS app using SwiftUI where we play background audio (music) in the Welcome screen, with support for offline playback via local caching. 🔹 Feature Overview App fetches audio metadata from API Starts streaming audio (HLS .m3u8) immediately In parallel, downloads the raw audio file (.mp3) Once download completes: Switches playback from streaming → local file On next launch (offline mode), app plays audio from local storage 🔹 Issue This flow works perfectly on the Simulator, but on a real Apple TV device: Audio plays for a few seconds (2–5 sec) and then stops Especially after switching from streaming → local file No explicit AVPlayer error is logged Playback sometimes stops after UI updates or periodic API refresh 🔹 Implementation Details Using AVPlayer with AVPlayerItem Background audio controlled via a shared manager (singleton) Files stored locally using FileManager (currently using .cachesDirectory) Switching playback using: player.replaceCurrentItem(with: AVPlayerItem(url: localURL)) player.play() 🔹 Observations Works reliably on Simulator On device: Playback stops silently Seems related to lifecycle, buffering, or file access No issues when continuously streaming (without switching to local) 🔹 Questions Is there any limitation or known issue with AVPlayer when switching from streaming (HLS) to local file playback on tvOS? Are there specific requirements for playing locally cached media files on tvOS (e.g., file location, permissions, or sandbox behavior)? What is the recommended storage location and size limit for cached media files on tvOS? We understand tvOS has limited persistent storage Is .cachesDirectory the correct approach for this use case? Are there known differences in AVPlayer behavior between Simulator and real Apple TV devices (especially regarding buffering or lifecycle)? What is the recommended approach for implementing offline background audio on tvOS apps? 🔹 Goal We want to implement a reliable system where: Audio streams initially Seamlessly switches to local file after download Continues playing without interruption Supports offline playback on subsequent launches Any guidance or best practices would be greatly appreciated. Thank you!
0
0
23
15h
tvOS: Background audio + local caching works on Simulator but stops on real Apple TV device
Description: I’m developing a tvOS app using SwiftUI where we play background audio (music) in the Welcome screen, with support for offline playback via local caching. Feature Overview: App fetches audio metadata from API Starts streaming audio (HLS .m3u8) immediately In parallel, downloads the raw audio file (.mp3) Once download completes: Switches playback from streaming → local file On next launch (offline mode), app plays audio from local storage Issue: This flow works perfectly on the Simulator, but on a real Apple TV device: Audio plays for a few seconds (2–5 sec) and then stops Especially after switching from streaming → local file No explicit AVPlayer error is logged Playback sometimes stops after UI updates or periodic API refresh Implementation Details: Using AVPlayer with AVPlayerItem Background audio controlled via a shared manager (singleton) Files stored locally using FileManager (currently using .cachesDirectory) Switching playback using: player.replaceCurrentItem(with: AVPlayerItem(url: localURL)) player.play() Observations: Works reliably on Simulator On device: -- Playback stops silently -- Seems related to lifecycle, buffering, or file access No issues when continuously streaming (without switching to local) Questions: Is there any limitation or known issue with AVPlayer when switching from streaming (HLS) to local file playback on tvOS? Are there specific requirements for playing locally cached media files on tvOS (e.g., file location, permissions, or sandbox behavior)? What is the recommended storage location and size limit for cached media files on tvOS? We understand tvOS has limited persistent storage Is .cachesDirectory the correct approach for this use case? Are there known differences in AVPlayer behavior between Simulator and real Apple TV devices (especially regarding buffering or lifecycle)? What is the recommended approach for implementing offline background audio on tvOS apps? Goal: We want to implement a reliable system where: Audio streams initially Seamlessly switches to local file after download Continues playing without interruption Supports offline playback on subsequent launches Any guidance or best practices would be greatly appreciated. Thank you!
0
0
35
15h
Live Activity Not Updating Frequently for Offline Music App (Lyrics Sync Issue)
Hi everyone, I’m currently implementing Live Activities in my music app to display real-time lyrics on the Lock Screen. The app works fully offline, so I’m not using push updates or push tokens. Instead, I’m updating the Live Activity locally as each new line of lyrics is played (essentially near real-time updates synced with the song). However, I’m running into an issue where the Live Activity UI is not updating reliably or frequently enough. Even though I’m calling the update method for each lyric line, the changes are either delayed or not reflected at all. Here’s some additional context: • The app runs fine in the background (verified via battery usage and playback behavior) • Live Activity is successfully created and initially displayed • Updates are triggered locally (no push notifications involved) • Updates are happening quite frequently (per lyric line) • No crashes or errors are observed My questions: 1. Is there a system-imposed throttling limit on how frequently Live Activities can be updated locally? 2. Are there recommended update intervals for smooth UI updates (e.g., for use cases like lyrics or timers)? 3. Does Live Activity deprioritize updates for offline apps or background execution? 4. Are there any additional configurations or capabilities required to ensure consistent updates? 5. Is using something like AsyncStream or other concurrency patterns helpful in this case? 6. Are there any undocumented limitations or best practices for high-frequency updates? 7. Is there any private or internal API used by Apple apps (like Music) that allows smoother real-time updates? My goal is to achieve smooth, near real-time lyric updates similar to Apple Music’s Now Playing experience. Any guidance, best practices, or clarification would be greatly appreciated. Thanks in advance!
0
0
26
12h
Using Observations with SwiftData @Model
I want to use the Observations AsyncSequence on some SwiftData @Model instances to determine if internal calculations need to be done. When a simple property is linked to the Observations it fires CONTINUOUSLY even though no change is made to the model property. Also, when I try to observe a property which is a list of another @Model type the Observations sequence does not fire when I add or remove items. I am hoping to use the async-algorithm's merge function so all the associated sequences can be combined since if any of the associated events should fire the calculation event.
Replies
4
Boosts
0
Views
2.8k
Activity
Jan ’26
JavaScript/Swift Interoperability
I think that it would be helpful to have better interoperability between Swift and JavaScript. There are a lot of useful packages on NPM that don't have equivalents for Swift. It would be helpful if Apple provided easier ways to use NPM packages in a Swift project. Currently, the JavaScriptCore framework is missing many standard things used in many packages, like the fetch API. It would be helpful to be able to run sandboxed JavaScript code inside of a Swift app but allow access to specific domains, folders, etc., using a permissions system similar to Deno.
Replies
6
Boosts
1
Views
3.3k
Activity
Jan ’26
vDSP.DiscreteFourierTransform failed to initialize with 5 * 5 * 2^n count
I am implementing the FFT using vDSP.DiscreteFourierTransform. According to the official documentation, the count parameter has requirements as outlined below: /// The `count` parameter must be: /// * For split-complex real-to-complex: `2ⁿ` or `f * 2ⁿ`, where `f` is `3`, `5`, or `15` and `n >= 4`. /// * For split-complex complex-to-complex: `2ⁿ` or `f * 2ⁿ`, where `f` is `3`, `5`, or `15` and `n >= 3`. /// * For interleaved: `f * 2ⁿ`, where `f` is `2`, `3`, `5`, `3x3`, `3x5`, or `5x5`, and `n>=2`. Despite adhering to these specifications in theory, my attempt to initialize an interleaved DFT with count = 2 * 2 * 5 * 5 (equivalent to 5×5 × 2²) resulted in a failure. Below is the code snippet I used for the initialization: do { let dft = try vDSP.DiscreteFourierTransform( previous: nil, count: 2 * 2 * 5 * 5, direction: .forward, transformType: .complexReal, ofType: DSPComplex.self ) print(dft) } catch { print("DFT init failed:", error) } Could somebody more knowledgeable with these APIs have a look? Thanks!
Replies
1
Boosts
0
Views
694
Activity
Jan ’26
iOS and Android
I currently have a iOS app live on the App Store but I also want to release it on Android, the whole code is in Swift so would that be possible or would I have to rewrite my whole apps code in a different coding language.
Replies
2
Boosts
0
Views
2.8k
Activity
Jan ’26
init?(coder: NSCoder) or init?(coder: (NSCoder?))
In this code, I use in some places required init?(coder: (NSCoder?)) { // Init some properties super.init(coder: coder!) } And in other places required init?(coder: NSCoder) { super.init(coder: coder) // Init some properties } Both seem to work. Is there a preferred one ? In which cases ? Or should I always use the second one ? And can super be called at anytime ?
Replies
2
Boosts
0
Views
674
Activity
Feb ’26
Calling a Objc method directly from C
I would like to avoid the middle man and call Objective C directly from C Currently I do this This is called from a dispatch table in a pure C file _ctx->mt_render_funcs.mtlEnd(_ctx); Which calls this routine in a obj c file .m void mtlEnd(MTRenderContext mt_ctx) { // Call the Objective-C method using Objective-C syntax [(__bridge id) mt_ctx->mt_render_funcs.mtlObj mtlEnd]; } Which ends up here... in ObjC #pragma mark mtlEnd (void)mtlEnd { // vertex buffer size_t size; size = sizeof(Vertex4ColorNormalTex) * _ctx->vert_eng.current_vertex; [_currentRenderEncoder setVertexBytes:_ctx->vert_eng.vertices length: size atIndex: VertexInputIndexVertices]; [_currentRenderEncoder drawPrimitives:(MTLPrimitiveType)_ctx->vert_eng.prim_type vertexStart:0 vertexCount:_ctx->vert_eng.current_vertex]; } It would simplify this to get rid of one call and call ObjC directly. The other idea is I want to use GCD and put a lock / unlock on the call from C to ensure thread safety so I can use GCD to dispatch a thread to do the ObjC routines. I want to stick with C as the foundation so it can be used directly from C or a FFI interface from other languages. But Metal works well in ObjC and I would prefer to use that. Thanks ahead of time.
Replies
3
Boosts
0
Views
1.2k
Activity
Feb ’26
Bridging Header doesn't seem to include my Swift class
I think have done everything by the book. I added a small Swift file to my Objective-C project. This is code in the project, not in a framework, so I did not use the public keyword: import Foundation @objc TestClass: NSObject { @objc init(){} } Adding this file prompted creating a bridging header and it should have added TestClass into it. I added the import to the Objective-C .m file. This didn't produce an error so the file must be there: #import "SoftServePro-Bridging-Header.h" I made a property for an instance of the class in the .h file: @property(nonatomic,strong) TestClass *test; I cleaned the project and did one compile for the precompiler to populate the bridging header. I have set Defines Module to Yes in Build Settings -> Packaging. I added a line in the .m code to create a TestClass: self.test=[[TestClass alloc]init]; And for my trouble I get the error message Now, this looks to me like TestClass is not in my bridging header because if it were it should know exactly what TestClass is, not just consider it a forward declaration. I haven't figured out any way to look at the actual contents of the bridging header after precompile, so I don't know if TestClass is there or not. The ONLY thing that I have not followed is that the documentation I have read says to put the bridging header in the same folder as the .xcodeproj file, but Xcode put it in with all the source code files (one folder down) and who am I to argue with Xcode??
Replies
3
Boosts
0
Views
1.3k
Activity
Mar ’26
Data Disappeared
Hi, writing a database app for storing equipment details. Spent the day doing minor changes and tidying with many backups made, and always re-building to check its all working. Everything ok but then next build looses all data, what's the best thing to check to see if the data is still there, any help would be fantastic.
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’26
Apple Silicon calling printf
What is the proper way to pass arguments to printf with multiple variables using ARM64 Apple Silicon? Example: fOutputStr: .asciz "Element[%d] = %d\n" // formated output string for an output of: Element[4] = 9 This code (see below) works on Raspberry Pi 5, on my Mac Studio, I am getting this output, Element[9] = 1871655168 What do I need to do to use printf from an assembly language call with multiple variables? I am using the following code. ` .align 2 // memory alignment model for 64-bit ARMc #if defined(APPLE) .global _main // Provide program starting address to linker Mac OS _main: #else .global main // Raspian and Linux main: #endif // stack frame work setup START stp x29, x30, [sp, -16]! str x20, [sp, -16]! mov x29, sp // stack frame work setup END // setup printf call #if defined(APPLE) adrp x0, fOutputStr@PAGE add x0, x0, fOutputStr@PAGEOFF #else ldr x0, =fOutputStr #endif mov w1, #4 mov w2, #9 print_brk: #if defined(APPLE) stp X0, X1, [SP, #-16]! stp X2, X3, [SP, #-16]! bl _printf ldp X2, X3, [SP], #16 ldp X0, X1, [SP], #16 #else bl printf #endif done: // closing stack frame work ldr x20, [sp],16 ldp x29, x30, [sp],16 // exit mov w0, wzr ret .data .align 4 // intArrayPtr: .word 3,7,5,2,4,8 // word, each value is offset by 4 fOutputStr: .asciz "Element[%d] = %d\n" // formated output string
Replies
6
Boosts
1
Views
766
Activity
4w
Why is the Documentation full of Conundrums?
I'm trying to learn and focus on the task and your examples keep having hidden conundrums in them. Here is an example that got me snagged for hours last night going, Well what the F do they want me to name it? What is it you want me to learn here? Because you pose a giant riddle of name something that you should be given a name for... My friend said to me that this is a common thing you will have to do and they were right however... What are you asking me to do? Get stuck on the variable naming problem where I'm going... Yeah those are math terms from 20+ years ago and I have no idea how to classify those terms... Are you asking me that? No. So why is that in the problem. These conundrums mixed in with legitimate problems honestly make me not want to learn Swift at all.
Replies
3
Boosts
0
Views
310
Activity
3w
Attached macro loses generated source file
I’m seeing what looks like a compiler / macro-expansion / build-pipeline issue. Environment: Xcode 26.4 RC (17E192, latest); I believe it is also reproducible on earlier versions. github source code I reduced this to a very small macOS/iOS app plus a local macro package. The app logic is trivial, but app exits immediately on launch with code 138 Important observations: If I inline everything into a single file, the problem disappears. I also see an error like this during investigation: The file path does not exist on the file system: /var/folders/.../swift-generated-sources/@__swiftmacro_18MacroFeedbackRepro20MountActivationState17PreservedRawValuefMm_.swift That makes me suspect this is not an application logic issue, but something in macro expansion / generated source handling / compiler pipeline.
Replies
2
Boosts
0
Views
1.8k
Activity
3w
On iPad with Swift Playgrounds: How to open chapter as a playground?
Note On a Mac with Xcode installed, or on an iPad with Swift Playgrounds, you can open this chapter as a playground. Playgrounds allow you to edit the code listings and see the results immediately. (Note in page 3) (I would like to open the chapter or book: Swift Programming Language in Swift Playground on iPad) https://books.apple.com/ve/book/the-swift-programming-language-swift-5-7-beta/id1002622538?l=en-GB Best regards
Replies
2
Boosts
0
Views
1k
Activity
3w
How works Experiment (Documentation) in Swift Playground?
Experiment Create a constant with an explicit type of Float and a value of 4. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour
Replies
3
Boosts
0
Views
1.6k
Activity
3w
tvOS: Background audio + local caching works on Simulator but stops on real Apple TV device
Description: I’m developing a tvOS app using SwiftUI where we play background audio (music) in the Welcome screen, with support for offline playback via local caching. 🔹 Feature Overview App fetches audio metadata from API Starts streaming audio (HLS .m3u8) immediately In parallel, downloads the raw audio file (.mp3) Once download completes: Switches playback from streaming → local file On next launch (offline mode), app plays audio from local storage 🔹 Issue This flow works perfectly on the Simulator, but on a real Apple TV device: Audio plays for a few seconds (2–5 sec) and then stops Especially after switching from streaming → local file No explicit AVPlayer error is logged Playback sometimes stops after UI updates or periodic API refresh 🔹 Implementation Details Using AVPlayer with AVPlayerItem Background audio controlled via a shared manager (singleton) Files stored locally using FileManager (currently using .cachesDirectory) Switching playback using: player.replaceCurrentItem(with: AVPlayerItem(url: localURL)) player.play() 🔹 Observations Works reliably on Simulator On device: Playback stops silently Seems related to lifecycle, buffering, or file access No issues when continuously streaming (without switching to local) 🔹 Questions Is there any limitation or known issue with AVPlayer when switching from streaming (HLS) to local file playback on tvOS? Are there specific requirements for playing locally cached media files on tvOS (e.g., file location, permissions, or sandbox behavior)? What is the recommended storage location and size limit for cached media files on tvOS? We understand tvOS has limited persistent storage Is .cachesDirectory the correct approach for this use case? Are there known differences in AVPlayer behavior between Simulator and real Apple TV devices (especially regarding buffering or lifecycle)? What is the recommended approach for implementing offline background audio on tvOS apps? 🔹 Goal We want to implement a reliable system where: Audio streams initially Seamlessly switches to local file after download Continues playing without interruption Supports offline playback on subsequent launches Any guidance or best practices would be greatly appreciated. Thank you!
Replies
0
Boosts
0
Views
23
Activity
15h
tvOS: Background audio + local caching works on Simulator but stops on real Apple TV device
Description: I’m developing a tvOS app using SwiftUI where we play background audio (music) in the Welcome screen, with support for offline playback via local caching. Feature Overview: App fetches audio metadata from API Starts streaming audio (HLS .m3u8) immediately In parallel, downloads the raw audio file (.mp3) Once download completes: Switches playback from streaming → local file On next launch (offline mode), app plays audio from local storage Issue: This flow works perfectly on the Simulator, but on a real Apple TV device: Audio plays for a few seconds (2–5 sec) and then stops Especially after switching from streaming → local file No explicit AVPlayer error is logged Playback sometimes stops after UI updates or periodic API refresh Implementation Details: Using AVPlayer with AVPlayerItem Background audio controlled via a shared manager (singleton) Files stored locally using FileManager (currently using .cachesDirectory) Switching playback using: player.replaceCurrentItem(with: AVPlayerItem(url: localURL)) player.play() Observations: Works reliably on Simulator On device: -- Playback stops silently -- Seems related to lifecycle, buffering, or file access No issues when continuously streaming (without switching to local) Questions: Is there any limitation or known issue with AVPlayer when switching from streaming (HLS) to local file playback on tvOS? Are there specific requirements for playing locally cached media files on tvOS (e.g., file location, permissions, or sandbox behavior)? What is the recommended storage location and size limit for cached media files on tvOS? We understand tvOS has limited persistent storage Is .cachesDirectory the correct approach for this use case? Are there known differences in AVPlayer behavior between Simulator and real Apple TV devices (especially regarding buffering or lifecycle)? What is the recommended approach for implementing offline background audio on tvOS apps? Goal: We want to implement a reliable system where: Audio streams initially Seamlessly switches to local file after download Continues playing without interruption Supports offline playback on subsequent launches Any guidance or best practices would be greatly appreciated. Thank you!
Replies
0
Boosts
0
Views
35
Activity
15h
Live Activity Not Updating Frequently for Offline Music App (Lyrics Sync Issue)
Hi everyone, I’m currently implementing Live Activities in my music app to display real-time lyrics on the Lock Screen. The app works fully offline, so I’m not using push updates or push tokens. Instead, I’m updating the Live Activity locally as each new line of lyrics is played (essentially near real-time updates synced with the song). However, I’m running into an issue where the Live Activity UI is not updating reliably or frequently enough. Even though I’m calling the update method for each lyric line, the changes are either delayed or not reflected at all. Here’s some additional context: • The app runs fine in the background (verified via battery usage and playback behavior) • Live Activity is successfully created and initially displayed • Updates are triggered locally (no push notifications involved) • Updates are happening quite frequently (per lyric line) • No crashes or errors are observed My questions: 1. Is there a system-imposed throttling limit on how frequently Live Activities can be updated locally? 2. Are there recommended update intervals for smooth UI updates (e.g., for use cases like lyrics or timers)? 3. Does Live Activity deprioritize updates for offline apps or background execution? 4. Are there any additional configurations or capabilities required to ensure consistent updates? 5. Is using something like AsyncStream or other concurrency patterns helpful in this case? 6. Are there any undocumented limitations or best practices for high-frequency updates? 7. Is there any private or internal API used by Apple apps (like Music) that allows smoother real-time updates? My goal is to achieve smooth, near real-time lyric updates similar to Apple Music’s Now Playing experience. Any guidance, best practices, or clarification would be greatly appreciated. Thanks in advance!
Replies
0
Boosts
0
Views
26
Activity
12h