Hello, What is the best and Apple recommended way to get display name and its vendor information?
- The CoreGraphics framework provides ModelNumber and VendorNumber only.
- Looks like IOKit does not provide any documented way at all.
Are there any daemon safe way to get such information?
Thank you in advance, Pavel
Display and vendor information can be retrieved using Core Graphics' Quartz Display Services routines as shown below. As you have mentioned, the CGDisplayModelNumber(_:) and CGDisplayVendorNumber(_:) routines return numbers.
import Foundation import CoreGraphics var mainDisplay: CGDirectDisplayID = CGMainDisplayID() var displayCount: UInt32 = 0 let maxDisplays: UInt32 = 100 let displaysList: UnsafeMutablePointer<CGDirectDisplayID> = UnsafeMutablePointer<CGDirectDisplayID>.allocate(capacity: Int(maxDisplays)) var status: CGError = CGGetOnlineDisplayList(maxDisplays, displaysList, &displayCount) guard status == CGError.success else { fatalError("Couldn't get online displays list") } for displayIndex: Int in 0..<Int(displayCount) { let nthDisplayID: CGDirectDisplayID = displaysList[displayIndex] print("Display #\(displayIndex):") print(" main display: \(CGDisplayIsMain(nthDisplayID))") print(" online: \(CGDisplayIsOnline(nthDisplayID))") print(" model number: \(CGDisplayModelNumber(nthDisplayID))") print(" serial number: \(CGDisplaySerialNumber(nthDisplayID))") print(" unit number: \(CGDisplayUnitNumber(nthDisplayID))") print(" vendor number: \(CGDisplayVendorNumber(nthDisplayID))") if let displayModes: CFArray = CGDisplayCopyAllDisplayModes(nthDisplayID, nil ) { // dump(displayModes) } }
The CGDisplayIOServicePort(_:) routine returns a I/O Kit service port for the specified display but any results you are able to obtain using this service port are undocumented and subject to change at any time without notice. Also, use of this routine has been deprecated.
If you require additional information not provided by the Quartz Display Services routines then please file an enhancement request asking for routines providing the additional information you are interested in getting about connected displays. You can file an enhancement request using Feedback Assistant. Once you file the request, please post the Feedback number here.
If you're not familiar with how to file enhancement requests, take a look at Bug Reporting: How and Why?