如何检测iPhone 5c的颜色? [英] How to detect the colour of an iPhone 5c?

查看:172
本文介绍了如何检测iPhone 5c的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iPhone 5c发布后,我很好奇是否有人知道API如何获得iPhone 5c颜色?我相信每个人都会发现将相应的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的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆