Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get iPhone physical color using the API [duplicate]

After iPhone 5c announcement, i'm curious if anybody knows an API how to get an iPhone 5c colour? I'm sure everyone will find it convenient loading a corresponding UI colour scheme to the device colour.

I'm thinking about wrapping it in something like the UIDevice category, which will return a UIColor.

Update: @ColinE and @Ortwin Gentz has indicated the availability of private UIDevice instance method calls for it.

Please note, that in case of iPhone 5c, what you are really looking for is deviceEnclosureColor, as deviceColor will always return #3b3b3c, as it is a front colour.

method signature:

-(id)_deviceInfoForKey:(struct __CFString { }*)arg1

UIDevice category for it:

@interface UIDevice (deviceColour)

- (id)_deviceInfoForKey:(struct __CFString { }*)arg1;
- (NSString*)deviceColourString_UntilAppleMakesItPublic;
- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic;


@end

@implementation UIDevice (deviceColour)

- (NSString*)deviceColourString_UntilAppleMakesItPublic
{
    return [self _deviceInfoForKey:@"DeviceColor"];
}

- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic
{
    return [self _deviceInfoForKey:@"DeviceEnclosureColor"];
}


@end
like image 282
ambientlight Avatar asked Sep 12 '13 16:09

ambientlight


People also ask

How do I get the exact color on my iPhone?

Use the eyedropper tool to pick an exact color from an image on the screen. It can be useful if you want to match a color on the current document or one from another file. It's also handy if you see a color you like and want to save it for later.

Does iPhone have API?

Perform the API request with the Get Contents of URL actionIn the Shortcuts app on your iOS or iPadOS device, tap Show More in the Get Contents of URL action. The following options for the types of API requests you can make become available: GET allows you to retrieve data. POST allows you to create new data.

What is Assistivetouch?

Once activated, a large on-screen menu serves up frequently used functions for easier access and use. From the Accessibility Menu, you can lock your screen, take screenshots, open Google Assistant, Quick Settings, and Notifications, and adjust volume and brightness.

Can I duplicate app in iOS?

Creating a duplicate copy of an app icon is easy. Find the app in the App Library, then drag a new copy of it onto your Home Screen: Swipe to the App Library at the right edge of all your Home Screens. Look through the various folders or use the Search bar to find the app you want to duplicate.


3 Answers

The device colour (used to?) be encoded in the serial number of the device. I don't have a device to test on with them not officially released yet, but I imagine the solution will be similar to this:

Typical format of the iPhone SN is as follows: AABCCDDDEEF

AA = Factory and Machine ID
B = Year of Manufacturing (9 is 2009/2019, 0 is 2010/2020, 1 is 2011 and so on)
CC = Production Week (01 is week 1 of B, 11 is week 11 of B and so on)
DDD = Unique Identifier
EE = Color (A4=black)
F = size (S=16GB, T=32GB)

[Source]

There is more information on old techniques here


I would like to point out however, that I expect there isn't a supported method of getting the serial number. Assuming you'd only like to know this information so that you can customise your UI, I'd just put in a user option or ask them to select the colour of their device on first startup (or some other early point in the app-user life)

like image 176
James Webster Avatar answered Oct 08 '22 04:10

James Webster


There's a private API to retrieve both the DeviceColor and the DeviceEnclosureColor. In case of the iPhone 5c, the interesting part is the enclosure color (the device color = front color is always #3b3b3c).

UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(@"deviceInfoForKey:");
if (![device respondsToSelector:selector]) {
    selector = NSSelectorFromString(@"_deviceInfoForKey:");
}
if ([device respondsToSelector:selector]) {
    NSLog(@"DeviceColor: %@ DeviceEnclosureColor: %@", [device performSelector:selector withObject:@"DeviceColor"], [device performSelector:selector withObject:@"DeviceEnclosureColor"]);
}

I've blogged about this and provide a sample app:

http://www.futuretap.com/blog/device-colors/

Warning: As mentioned, this is a private API. Don't use this in App Store builds.

like image 25
Ortwin Gentz Avatar answered Oct 08 '22 03:10

Ortwin Gentz


A number of people on Twitter have cited the following method:

[[UIDevice currentDevice] _deviceInfoForKey:@"DeviceColor"]

Although I have not confirmed it myself.

like image 25
ColinE Avatar answered Oct 08 '22 03:10

ColinE