这两天平安的产品经理提出了一个奇葩的需求--“根据手机壳颜色改变主题”,导致程序员和产品经理大打出手,最后双双被开除。
刚开始看到这个帖子时,所有的软件开发群都炸了,那么到底能不能实现这个需求呢?答案是能,iOS提供了获取手机壳的API,安卓手机五花八门,估计想实现是有些悬的。具体该怎么实现呢,接下来请各位看官看下面的代码
注意,该方法是获取手机壳的颜色哦。
拿到了手机壳的颜色,就可以根据手机壳的颜色来改变主题颜色了。。。
但是该写法是私有api,所以上架会被拒,各位看官慎用,遇到产品经理提这样的需求的话,那就只好打一架了。。。
接下来把代码直接贴出来了,方便以后copy
//获取手机壳的颜色
-(void)getDeviceColor
{
UIDevice *currentDevice = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(@"deviceInfoForKey:");
if(![currentDevicerespondsToSelector:selector]) {
selector =NSSelectorFromString(@"_deviceInfoForKey:");
}
if([currentDevicerespondsToSelector:selector])
{
IMPimp = [currentDevicemethodForSelector:selector];
NSString*(*func)(id,SEL,NSString*) = (void*)imp;
NSString*deviceColor = func(currentDevice,selector,@"DeviceColor");
NSString*deviceEncColor = func(currentDevice,selector,@"DeviceEnclosureColor");
NSLog(@"deviceColor:%@,DeviceEnclosureColor:%@",deviceColor,deviceEncColor);
}
}