Install OS X volume on OS X 10.11 using Swift without using the deprecated AudioHardwareServiceSetPropertyData API

I found this code to mount a system volume using Swift. I got a warning while using the code in the playground.

AudioHardwareServiceSetPropertyData is deprecated in OS X 10.11

How do I update the code for OS X 10.11?

Thank. :)

+1


source to share


1 answer


As also suggested in this answer to a similar Objective-C question, I would suggest using ISSoundAdditions , which you can call from Swift as such:

NSSound.setSystemVolume(0.5)

      



The implementation -setSystemVolume

starts around line 113 in ISSoundAdditions.m in case you're wondering how they accomplish system volume tuning.

To clarify the actually disputed comment on my answer (since apparently deleted) there is no use of deprecated APIs in ISSoundAdditions when compiling with the El Capitan SDK is AudioHardwareServiceSetPropertyData

not used. AudioObjectSetPropertyData

is really an API to switch to if using deprecated AudioHardwareServiceSetPropertyData

, although as you can see from the ISSoundAdditions implementation I linked to, there is a bit of work to do (so I linked to the implementation first).

+5


source







All Articles