You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

tvOS平台编译AudioKit报错:'isiOSAppOnMac'仅适用于tvOS 14.0+

解决tvOS平台AudioKit编译错误:'isiOSAppOnMac' is only available in tvOS 14.0 or newer

问题根源

这段编译错误的核心是AudioKit的Settings.swift代码中,针对isiOSAppOnMac的版本检查未覆盖tvOS平台场景。尽管你的项目部署目标高于tvOS14,但编译器仍会判定这段代码可能在不符合版本要求的tvOS环境下执行,从而抛出错误。另外,isiOSAppOnMac属性本身对tvOS平台无实际意义(tvOS应用无法在Mac上运行),代码中多余的跨平台判断反而引发了兼容性问题。

解决方法

1. 临时修改AudioKit代码(快速修复)

直接修改Settings.swift中defaultAudioFormat的实现,针对tvOS平台单独处理,跳过Mac相关判断逻辑:

public static let defaultAudioFormat: AVAudioFormat = {
    #if os(tvOS)
        // tvOS 平台单独处理,无需判断Mac相关属性
        if #available(tvOS 18.0, *) {
            return AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2) ?? AVAudioFormat()
        }
        return AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2) ?? AVAudioFormat()
    #else
        // 原有iOS/macOS逻辑
        if #available(iOS 18.0, *) {
            if !ProcessInfo.processInfo.isMacCatalystApp && !ProcessInfo.processInfo.isiOSAppOnMac {
                return AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2) ?? AVAudioFormat()
            }
        }

        if #available(macOS 15.0, *) {
            return AVAudioFormat(standardFormatWithSampleRate: 48_000, channels: 2) ?? AVAudioFormat()
        }

        return AVAudioFormat(standardFormatWithSampleRate: 44_100, channels: 2) ?? AVAudioFormat()
    #endif
}()

2. 确认项目部署目标配置

  • 检查tvOS Target的部署目标:在Xcode中选中项目 -> 对应tvOS Target -> General标签页,确认Deployment Target设置为tvOS 14.0或更高。
  • 检查Podfile配置:确保Podfile开头指定正确的tvOS版本要求,执行pod install重新同步依赖:
    platform :tvos, '14.0'
    

3. 升级Xcode版本

若你使用的Xcode版本较旧,可能存在tvOS API版本检查的兼容性bug,建议升级到最新稳定版Xcode,确保编译器能正确识别tvOS的版本约束。

4. 提交官方修复

你可以在AudioKit的官方仓库提交Issue,告知维护者该tvOS平台的编译兼容性问题,推动官方修复代码逻辑。

内容的提问来源于stack exchange,提问作者user3578473

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 08:40:56