是否可以检测到安装了iOS 7的iPhone,iPad或iPod touch的颜色(黑白)?
我想在黑色或白色设备的情况下加载相应的UI外观。
是否可以检测到安装了iOS 7的iPhone,iPad或iPod touch的颜色(黑白)?
我想在黑色或白色设备的情况下加载相应的UI外观。
Answers:
有一个专用API可以检索DeviceColor和和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"]);
}
我已经对此进行了博客介绍,并提供了一个示例应用程序:
http://www.futuretap.com/blog/device-colors/
警告:如上所述,这是一个私有API。不要在App Store版本中使用此功能。
[NSObject -respondsToSelector:]。发行iOS 8时,您当前的逻辑可能无法正常运行。
                    deviceInfoForKey:iOS 8上的旧版本。我只需要检查两个选择器,看看它会响应哪个选择器。
                    这个问题的答案是“否”(到目前为止),我个人认为这不值多少钱,因为如果最终用户在iPhone上使用皮肤或其他外壳,该怎么办?
我建议最初询问用户“嘿,您的手机是什么颜色?” 然后相应地做。
此外,一项研究为我提供了这些信息,我不确定它是否为TRUE或是否会对您有所帮助。
序列号是关键:)
如果aabccdddeef是iPhone 4的序列号,则ee代表颜色(A4 =黑色)。我希望这里的一些人能与您一起检查此信息,以查看是否正确。
[IUDevice deviceColor]当前的SDK中没有东西。我正在做自己的研究,并随时通知您。
                    根据网上发布的信息,设备的颜色以序列号编码。iFixit的博客指出,倒数第二个位置持有该信息:xxxxxxxxCCx对于iPhone 4,A4表示黑色。似乎没有人拥有白色iPhone 4的代码,这很奇怪。在一个论坛上发帖表明可能是DZ。每个人似乎都在这里模仿其他人的信息。
另一个网站mydigitallife.com上有一篇文章,列出了各种较旧型号的颜色代码。在某些情况下,必须将三个位置一起读取才能确定颜色。据该网站称,所有iPhone 3G型号均具有3N颜色代码位置。3NP表示“黑色16GB 3G”,并3NQ表示“白色16GB 3G”。原始的(2G)iPhone也使用所有三个位置指示尺寸(没有颜色选项)。
关于SO的问题已经很多,可以帮助您获取设备的序列号。
出于调试目的,我编译了可能的deviceInfoForKey:键的更全面的列表。
需要注意的有趣问题(此问题)是DeviceRGBColor DeviceEnclosureRGBColor。该值似乎是一个整数,以形式表示RGB值0x00rrggbb。
作为参考,这里是我找到的所有键:
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        
deviceInfoForKey:是私人的。因此,所有这些键也是。