是否有任何方法或技巧可以检测 iPhone、iPad 或 iPod touch 所安装的 iOS 是黑色还是白色?
我想在黑色或白色设备上加载相应的 UI 皮肤。
是否有任何方法或技巧可以检测 iPhone、iPad 或 iPod touch 所安装的 iOS 是黑色还是白色?
我想在黑色或白色设备上加载相应的 UI 皮肤。
有一个私有 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发布时,你当前的逻辑可能会出现错误。 - Aaron BragerdeviceInfoForKey:
。 我只需检查两个选择器,看它响应哪一个即可。 - Aaron Brager我建议先询问用户“嘿,你的手机颜色是什么?”然后再进行相应操作。
此外,一项研究提供了这些信息,我不确定它是否正确或是否会对您有所帮助。
序列号是关键:)
如果aabccdddeef
是iPhone 4的序列号,则 ee
表示颜色,(A4 = 黑色)。我希望这里的一些人可以检查自己的信息,以查看这是否正确。
[IUDevice deviceColor]
这样的东西。我正在进行自己的研究,并会及时向您报告。 - totocaster仅代表个人意见 - 如果有人在寻找iPhone 5c的颜色,下面列出的颜色是从苹果官网上选出来的。
希望对每个人都有用:-)
iPhone 5c 颜色:
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
xxxxxxxxCCx
对于iPhone 4,A4
表示黑色。奇怪的是,没有人知道白色iPhone 4的代码。一个论坛帖子表明它可能是DZ
。每个人似乎都在重复别人的信息。3N
;3NP
表示“黑色16GB 3Gs”,而 3NQ
表示“白色16GB 3Gs”。原始的(2G)iPhone 也使用所有三个位置来指示大小(没有颜色选项)。为了调试目的,我编译了一个更全面的可能的deviceInfoForKey:
键列表。
需要注意的有趣键(针对此问题)是DeviceRGBColor
DeviceEnclosureRGBColor
。它们的值似乎是以0x00rrggbb
形式表示RGB值的整数。
下面是我找到的所有键作为参考:
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