为什么一些非常古老的AudioToolbox API(AudioComponentDescription)现在仅支持iOS 10.0+?
AudioUnit
已经有很长时间了,但是我发现很多API只支持iOS 10.0+?例如,AudioComponentDescription
,kAudioOutputUnitProperty_EnableIO
,kAudioOutputUnitProperty_SetInputCallback
。为什么一些非常古老的AudioToolbox API(AudioComponentDescription)现在仅支持iOS 10.0+?
这是Apple的错误吗?我可以在iOS 10.0之前的平台上使用这些API吗?他们会被视为私人API吗?
这是我经常用它来了解在OS X/IOS API的方式:
AudioComponentDescription在AudioComponent.h定义,让我们找到那个文件:
$ find/-name AudioComponent.h # Use sudo to avoid a lot of permission denied errors
在我系统我结束了这些结果:
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Versions/A/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioUnit.framework/Versions/A/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/AppleTVOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/AppleTVSimulator.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/iPhoneOS.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/iPhoneSimulator.sdk/System/Library/Frameworks/AudioUnit.framework/Headers/AudioComponent.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/MacOSX.sdk/System/Library/Frameworks/AudioUnit.framework/Versions/A/Headers/AudioComponent.h
所以现在我们可以随便挑头文件中的一个,例如一个在iPhoneOS.platform文件夹中。
在那里,我们发现AudioComponentDescription没有任何可用性宏的定义:
typedef struct AudioComponentDescription {
OSType componentType;
OSType componentSubType;
OSType componentManufacturer;
UInt32 componentFlags;
UInt32 componentFlagsMask;
} AudioComponentDescription;
所以,这一次似乎可用任何IOS版本。
(我还检查kAudioOutputUnitProperty_EnableIO
和kAudioOutputUnitProperty_SetInputCallback
,两者都是有不可用性限制)
我还与IOS 8.1运行一个简单迅捷IOS应用测试了它:
let systemVersion = UIDevice.current.systemVersion
var desc = AudioComponentDescription();
desc.componentType = kAudioOutputUnitProperty_EnableIO; // This makes no sense at all, but proves the usability
desc.componentSubType = kAudioOutputUnitProperty_SetInputCallback; // This makes no sense at all, but proves the usability
print("IOS Version: \(systemVersion)");
print(desc);
与控制台输出:
IOS Version: 8.1
AudioComponentDescription(componentType: 2003, componentSubType: 2005, componentManufacturer: 0, componentFlags: 0, componentFlagsMask: 0)
所以,在回答你的问题:
这是Apple的错误吗?
我假设您指的是SDK的可用性,如Apple最近在线API文档中所示。 这可能没有错,但我不知道确切的原因是什么。我想嫌疑人它与Apple最近更新所有API文档有关。 要点是,如果你想知道实际情况:读取头文件。
我可以在iOS 10.0之前的平台上使用这些API吗?
如上所示,是的。
他们会被视为私人API吗?
这很奇怪,因为它们是SDK文件夹内的头文件,这表明任何人都可以将它们用作所提供的SDK的一部分。
要了解有关可用性宏的更多信息,请阅读其中一个SDK文件夹(使用上述搜索方法)中Availability.h的内容。
很好的答案!如果没有可用性宏,你的意思是使用安全吗? – feihu
是的,否则你会看到'__OSX_AVAILABLE_STARTING(__ MAC_10_6,__ IPHONE_2_0)'(从OS X 10.6和IOS 2.0开始)。或'__OSX_AVAILABLE_STARTING(__ MAC_10_11,__IPHONE_NA)'(可从OS X 10.11开始使用,并且不可用于IOS)。或者'__OSX_AVAILABLE_BUT_DEPRECATED(__ MAC_10_3,__MAC_10_7,__IPHONE_2_0,__IPHONE_4_1)'(从OS X 10.3到10.7,从2.0到4.1包括IOS) –
非常感谢。 – feihu