Attention! For Japanese customers, my Japanese blog might help.

Jul 21, 2016

Get display names without using CGDisplayIOServicePort()

NOTE: This article is the English version of my Japanese article.

Because CGDisplayIOServicePort() has been deprecated in 10.9, I was looking for alternatives to get display names.

There was the same question in Stack Overflow:
objective c - CGDisplayIOServicePort is deprecated in OS X >= 10.9, how to replace? - Stack Overflow

By a comment to the question above, there was seemed to be another implementation in a repository in GitHub.

To see how the functionality is implemented, it may be a good idea to see diff:
Replace CGDisplayIOServicePort with a workaround implementation · 8101d7a · glfw/glfw

Concretely, a function IOServicePortFromCGDisplayID() was added and used instead of CGDisplayIOServicePort(), which was used in getDisplayName().

You can use the functionality by copying IOServicePortFromCGDisplayID and getDisplayName() from the newest source code to your code.
(You should add IOKit.framework and include IOGraphicsLib.h if not.)

But, it may be needed to customize the code to convert to NSString or specify a locale for your environment.