40

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
James Webster
  • 31,873
  • 11
  • 70
  • 114
ambientlight
  • 7,212
  • 3
  • 49
  • 61
  • Clever idea!!! You may get some hints from discussion here http://stackoverflow.com/questions/8463212/detecting-color-of-iphone-ipod-touch – Sonny Saluja Sep 12 '13 at 16:39
  • I don't think there is a public API available to to that. – Nikola Kirev Sep 12 '13 at 16:40
  • 1
    Ok got it, but It seems quite logical to integrate an UI colour scheme with a device colour, so maybe they will provide something, don't u think? – ambientlight Sep 12 '13 at 16:41
  • Yes, iOS 7 is still under NDA, and will be until the official release date, 18 September 2013. Are you a registered, paying developer? If so, ask on the Apple Developer forums. – stevekohls Sep 12 '13 at 17:21
  • 1
    I am, and I already did. Here's the link: https://devforums.apple.com/message/887633#887633 – ambientlight Sep 12 '13 at 17:25
  • This question appears to be off-topic because it deals with technology which is still under NDA. – Philipp Schlösser Sep 12 '13 at 19:24
  • 2
    Questions covered by a third party NDA are not offtopic in StackOverflow. See http://meta.stackexchange.com/a/94488/162235 – Jano Sep 12 '13 at 23:31
  • 1
    If I where you, I would have 5 different UI themes ready and let the user chose. As a user, it's very annoying when a device/software stubbornly outsmarts you and doesn't let you set things up the way you would prefer. Some people might want to mix device/UI colors, e.g. just like the Apple cases. – Nicolas Miari Oct 01 '13 at 02:36
  • yes, I do have different UI colour schemes, which user can choose from settings view, but for me the default scheme should be the same as the device colour. This all is just to avoid asking user on the first launch - which UI colour scheme do you want to choose. – ambientlight Oct 01 '13 at 02:43
  • 2
    Ah, but the real question is what is the API for *changing* the color? – Hot Licks Oct 12 '13 at 13:01
  • Hurden, the device color is always #3b3b3c in case of the iPhone 5c, so I think your update is a bit misleading. Check my answer. – Ortwin Gentz Oct 14 '13 at 08:36
  • Yeah, I updated it, just never tested it on 5c, still have to wait 1 month till we can get it here. – ambientlight Oct 15 '13 at 01:32
  • Is this ok to use? Just want to be sure my app won't be rejected if it's not. – Justin Cabral Apr 10 '14 at 01:11
  • It is more likely it will get rejected. – ambientlight Apr 11 '14 at 06:57

4 Answers4

13

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)

Community
  • 1
  • 1
James Webster
  • 31,873
  • 11
  • 70
  • 114
8

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
3

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

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

Although I have not confirmed it myself.

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • 3
    Note that the _ indicates this is a private method. – Jano Sep 21 '13 at 13:44
  • So, How do we use to this method ? :/ – Arnaud Nelissen Sep 21 '13 at 14:05
  • 8
    @Amaud, the answer is that you don't, at least not in an app you want to submit to the app store. – Duncan C Sep 24 '13 at 00:14
  • 2
    @Arnaud, the answer to how to use private API method is to create a category on UIDevice, and add the following private signature into interface section -(id)_deviceInfoForKey:(struct __CFString { }*)arg1; This will return an NSString with a colour name. If u ran it on simulator it will return @"unknown". (method signature is taken from complete listing of API available - https://github.com/nst/iOS-Runtime-Headers) – ambientlight Sep 24 '13 at 10:23
  • The device color is always #3b3b3c in case of the iPhone 5c so it doesn't help much. Check my answer. – Ortwin Gentz Oct 14 '13 at 08:37
0

This may help you...

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

Ref: Detecting Color of iPhone/iPad/iPod touch?

Community
  • 1
  • 1
Krupal Ghorpade
  • 137
  • 1
  • 15