是否可以检测到安装了iOS 7的iPhone,iPad或iPod touch的颜色(黑白)?

我想在黑色或白色设备的情况下加载相应的UI外观。

最佳答案

有一个专用API可以同时检索DeviceColorDeviceEnclosureColor

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/

警告:如前所述,这是一个私有(private)API。不要在App Store版本中使用此功能。

10-05 20:26