Skip to content

Latest commit

 

History

History
25 lines (13 loc) · 1.56 KB

README.md

File metadata and controls

25 lines (13 loc) · 1.56 KB

DeviceColor

⚠️ Don't use this code in production - device color is part of the private API ⚠️

About

My favorite addition to demo apps or hackathon projects is to add different color schemes for different device colors. Can be achieved easily in Objective-C using the private api. (Please note you should not publish apps using the private api).

Note it's possible to accomplish the same results with a bridging header, but I wanted a 'pure' Swift solution. Inspiration and help from this stackoverflow post.

If someone know or created a public color scheme for all different devices please ping me. I'd like to add it to my example project.

Usage

Fork or download the project, put the extension UIDevice+DeviceColor.swift in your own project, get the color using UIDevice.current.deviceInfoForKey(key: "DeviceEnclosureColor") or UIDevice.current.deviceInfoForKey(key: "DeviceColor"). the returned string can be parsed with an extension to UIcolor e.g arshad's gist or similar.

Preferably you want to check if the method is available before calling the method to avoid crashes if the API changes.

Acknowledgment

Check out ortwingentz's example project in Objective-C. He also made a collection of device colors 🙌! Also, please dupe his radar, hopefully we get to use the device color in future iOS versions.

License

MIT, see LICENSE.md