问题描述
iPhone 5c 发布后,我很好奇是否有人知道如何获得 iPhone 5c 颜色的 API?我相信每个人都会发现将相应的 UI 配色方案加载到设备颜色中会很方便.
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.
我正在考虑将其包装在 UIDevice 类别中,这将返回 UIColor.
I'm thinking about wrapping it in something like the UIDevice category, which will return a UIColor.
更新:@ColinE 和 @Ortwin Gentz已指示私有 UIDevice 实例方法调用它的可用性.
Update:@ColinE and @Ortwin Gentz has indicated the availability of private UIDevice instance method calls for it.
请注意,在 iPhone 5c 的情况下,您真正需要的是 deviceEnclosureColor,因为 deviceColor 将始终返回 #3b3b3c,因为它是一种前颜色.
方法签名:
-(id)_deviceInfoForKey:(struct __CFString { }*)arg1
UIDevice 类别:
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
推荐答案
有一个私有 API 来检索 DeviceColor
和 DeviceEnclosureColor
.对于 iPhone 5c,有趣的部分是外壳颜色(设备颜色 = 正面颜色始终为 #3b3b3c).
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/
警告:如前所述,这是一个私有 API.不要在 App Store 版本中使用它.
这篇关于如何检测 iPhone 5c 的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!