毛叔老矣 | Live life with a passion!

二/10

8

获取和设置iphone屏幕亮度

首先,Apple是不允许应用程序这样做的。当然,所谓的不允许,是你提交的应用会被reject。我们如果不提交给AppStore,苹果当然就管不着了,呵呵。
实现方法来自于iPhone Dev SDK Forum
读取屏幕亮度:

1
2
3
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]

设置屏幕亮度:

1
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.一般,会涉及到调节屏幕亮度的程序,都会搭配防止休眠的功能,代码很简单:

1
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

RSS Feed

还没有任何评论。

Leave a comment!

« Objective-C中的字符串格式化输出

被垃圾回复严重困扰 »

Copyright © 2009 HunterX all right reserved.