一种方式是用GSEventSetBacklightLevel的方式设置的,但是会被reject回来的,(在2.0上)
NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
[bl release]
设置屏幕亮度:
GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
在main view 上面再加個view蓋上
把userInteractionEnabled 設成NO, backgroundcolore設成黑色
觸發action時改變這個view 的alpha值
就能做出假的光源控制了
实现方法来自于iPhone Dev SDK Forum:
读取屏幕亮度:
NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
[bl release]
设置屏幕亮度:
GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
后续的问题:
1.据说读取屏幕亮度的方法只在2.x的firmware有效,因为今天apple mini没在手里,暂时无法验证。
2.使用上述功能前,需要进入GraphicsServices.h。
3.因为是私有API,GSEventSetBacklightLevel(float value)这个方法,可能需要自己额外在GraphicsServices.h里定义一下(有待验证),或者使用ToolChain编译。
4.一般,会涉及到调节屏幕亮度的程序,都会搭配防止休眠的功能,代码很简单:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
一个偏方
读取屏幕亮度:
NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue]; //a variable to store the previous level so you can reset it.
[bl release]
设置屏幕亮度:
GSEventSetBacklightLevel(newLevel); //The new level: 0.0 - 1.0.
注意:GSEventSetBacklightLevel(float value)这个方法,可能需要自己额外在GraphicsServices.h里定义一下
不然有可能不能通过苹果的审核....因为这个方法像是个擦边球...有点像私有的API