Detecting Color of iPhone/iPad/iPod touch?

南楼画角 提交于 2019-12-17 02:22:18

问题


Is there any way or hack to detect on what color (black / white) iPhone, iPad or iPod touch the iOS is installed?

I want to load corresponding UI skins in case of Black or White devices.


回答1:


There's a private API to retrieve both the DeviceColor and the DeviceEnclosureColor.

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.




回答2:


The answer to the question is NO (as of now) and personally I don't think it's worth much, because what if the end-user uses a skin or an additional casing for his iPhone?

I'd suggest to initially ask the user "Hey, what's the color of your phone?" and then do accordingly.


Additionally, a research provided me with this information, I'm not sure if it's TRUE or if is going to help you.

The serial number is the key :)

If aabccdddeef is the serial number of the iPhone 4, ee represents the Color, (A4=black). I hope some of you here check this information with yours to see if this is true.




回答3:


Just my 2 cents worth - if anyone is looking for the iPhone 5c colors, the colors below are picked from the apple website.

Hope it is of use to anyone:-)

iPhone 5c Colors:

Green
R   179
G   243
B   142
HEX #B3F38E

Blue
R   123
G   195
B   252
HEX #7BC3FC

Yellow
R   255
G   243
B   141
HEX #FFF38D

Red
R   252
G   132
B   142
HEX #FF848E

White
R   239
G   239
B   239
HEX #EFEFEF



回答4:


According to information sprinkled around the web, the color of the device is encoded in the serial number. iFixit's blog indicates that the third- and second-to-last positions hold the information: xxxxxxxxCCx For an iPhone 4, A4 indicates black. No one seems to have the code for a white iPhone 4, which is strange. One forum posting indicates that it might be DZ. Everyone seems to be just parroting everyone else's information here.

Another site, mydigitallife.com, has an article listing the color codes for various older models. In some cases, the three positions have to be read together in order to determine the color. According to this site, all iPhone 3Gs models have 3N in the color code position; 3NP indicates "Black 16GB 3Gs", and 3NQ indicates "White 16GB 3Gs". The original (2G) iPhone also uses all three positions to indicate size (there were no color options).

There are already a number of questions here on SO that will help you to get the device's serial number.




回答5:


As others have noted, no, there is no official way of getting this information. Apple clearly knows (look in iTunes when you sync), so they could make it available. Might be worth raising a Radar.




回答6:


For debugging purposes I compiled a more comprehensive list of of possible deviceInfoForKey: keys.

Interesting keys to note (for this question) are DeviceRGBColor DeviceEnclosureRGBColor. The values appear to be an integer that represent the RGB value in the form 0x00rrggbb.

Here, for reference, are all the keys I found:

ActiveWirelessTechnology        
AirplaneMode        
assistant        
BasebandCertId        
BasebandChipId        
BasebandPostponementStatus        
BasebandStatus        
BatteryCurrentCapacity        
BatteryIsCharging        
BluetoothAddress        
BoardId        
BootNonce        
BuildVersion        
CertificateProductionStatus        
CertificateSecurityMode        
ChipID        
CompassCalibrationDictionary        
CPUArchitecture        
DeviceClass        
DeviceColor        
DeviceEnclosureColor        
DeviceEnclosureRGBColor        
DeviceName        
DeviceRGBColor        
DeviceSupportsFaceTime        
DeviceVariant        
DeviceVariantGuess        
DiagData        
dictation        
DiskUsage        
EffectiveProductionStatus        
EffectiveProductionStatusAp        
EffectiveProductionStatusSEP        
EffectiveSecurityMode        
EffectiveSecurityModeAp        
EffectiveSecurityModeSEP        
FirmwarePreflightInfo        
FirmwareVersion        
FrontFacingCameraHFRCapability        
HardwarePlatform        
HasSEP        
HWModelStr        
Image4Supported        
InternalBuild        
InverseDeviceID        
ipad        
MixAndMatchPrevention        
MLBSerialNumber        
MobileSubscriberCountryCode        
MobileSubscriberNetworkCode        
ModelNumber        
PartitionType        
PasswordProtected        
ProductName        
ProductType        
ProductVersion        
ProximitySensorCalibrationDictionary        
RearFacingCameraHFRCapability        
RegionCode        
RegionInfo        
SDIOManufacturerTuple        
SDIOProductInfo        
SerialNumber        
SIMTrayStatus        
SoftwareBehavior        
SoftwareBundleVersion        
SupportedDeviceFamilies        
SupportedKeyboards        
telephony        
UniqueChipID        
UniqueDeviceID        
UserAssignedDeviceName        
wifi        
WifiVendor        


来源:https://stackoverflow.com/questions/8463212/detecting-color-of-iphone-ipad-ipod-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!