0

AudioUnit has been available for a long time, however I found lots of APIs only supports iOS 10.0+? e.g., AudioComponentDescription, kAudioOutputUnitProperty_EnableIO, kAudioOutputUnitProperty_SetInputCallback.

Is it the mistake by Apple? Can I use these APIs on the platform before iOS 10.0? Would they be treated as private API?

feihu
  • 1,935
  • 16
  • 24

1 Answers1

1

This is the way I usually use to find out about the API's on OS X / IOS:

AudioComponentDescription is defined in AudioComponent.h, so let's find that file:

$ find / -name AudioComponent.h # Use sudo to avoid a lot of permission denied errors

On my system I end up with these results:

/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

So now we can just pick one of the header files, for example the one in the iPhoneOS.platform folder.

There we find the definition of AudioComponentDescription without any availability macro's:

typedef struct AudioComponentDescription {
    OSType              componentType;
    OSType              componentSubType;
    OSType              componentManufacturer;
    UInt32              componentFlags;
    UInt32              componentFlagsMask;
} AudioComponentDescription;

So, this one seems to be available on any IOS version.

(I also checked kAudioOutputUnitProperty_EnableIO and kAudioOutputUnitProperty_SetInputCallback, both are there without availability restrictions)

I also tested it with a simple Swift IOS app running on IOS 8.1:

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);

With the console output:

IOS Version: 8.1
AudioComponentDescription(componentType: 2003, componentSubType: 2005, componentManufacturer: 0, componentFlags: 0, componentFlagsMask: 0)

So, in answer to your questions:

Is it a mistake by Apple?

I assume you mean the SDK availability as show on the recent online API documentation from Apple. It'll probably be no mistake, but I don't know what the exact reason is. I suspect it has to do with Apple updating all their API documentation recently. Point is, if you want to know what's really going on: read the header files.

Can I use these APIs on the platform before iOS 10.0?

As shown above, yes.

Would they be treated as private API?

That would be weird as these are header files inside the SDK folders which suggests anyone can use them as part of the provided SDK.

To learn more about the availability macros read the contents of Availability.h in one of the SDK folders (using the search method above).

Ruurd Adema
  • 920
  • 7
  • 17
  • Great answer! Do you mean it's safety to use if there is no availability macro? – feihu Jun 09 '17 at 11:13
  • Yes, otherwise you would see something like `__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_2_0)` (available starting from OS X 10.6 and IOS 2.0). Or `__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_NA)` (available starting from OS X 10.11 and not available on IOS). Or `__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3, __MAC_10_7, __IPHONE_2_0, __IPHONE_4_1)` (available from OS X 10.3 up to and including 10.7, IOS from 2.0 up to and including 4.1) – Ruurd Adema Jun 09 '17 at 11:27
  • 1
    But I think there are better way to find methods and headers, use `COMMAND+SHIFT+O` in `XCode` is very convenient. – feihu Jun 09 '17 at 12:19
  • That is indeed very handy! – Ruurd Adema Jun 09 '17 at 12:25