改变背光水平,iPhone

时间:2009-11-22 01:33:04

标签: iphone objective-c brightness backlight

我在周围搜索了一种在iPhone上的应用程序中设置背光级别的方法。我在这里找到了一个解决方案:

http://www.iphonedevsdk.com/forum/29097-post3.html

我遇到的问题是,当我将此添加到我的应用程序时,我收到错误和警告。我的代码如下:

#include "GraphicsServices.h"

- (void) viewWillAppear:(BOOL)animated
{

NSNumber *bl = (NSNumber*) CFPreferencesCopyAppValue(CFSTR("SBBacklightLevel" ), CFSTR("com.apple.springboard"));
previousBacklightLevel = [bl floatValue];
//Error here : incompatible types in assignment

[bl release];   

GSEventSetBacklightLevel(0.5f);
// Warning here : implicit declaration of function 'GSEventSetBacklightLevel'

}

//...The rest of my app

- (void)applicationWillTerminate:(UIApplication *)TheNameOfMyAppIsHere
{
    GSEventSetBacklightLevel(previousBacklightLevel);
}

我不确定导致这种情况的原因。我也不知道我的.h文件中需要什么,但我有:

NSNumber *previousBacklightLevel;

编辑//已更改

NSNumber *previousBacklightLevel 

float previousBacklightLevel;

按照建议,这对赋值错误中的不兼容类型进行了排序。

现在离开了:

“_ GSEventSetBacklightLevel”,引自:

- MyAppViewController.o中的[MyAppViewController viewWillAppear:]

- MyAppViewController.o中的[MyAppViewController applicationWillTerminate]

未找到符号

collect2:ld返回1退出状态

不确定如何解决这个问题!

任何帮助将不胜感激,

//编辑

排除所有问题。感谢所有帮助过我的人。我真的很感激,并且不能等到我能回复一些问题。

非常感谢,

斯图

2 个答案:

答案 0 :(得分:5)

您收到警告的原因是GSEventSetBacklightLevel()是未在任何SDK标头中声明的私有API。如果您打算将此内容提交到应用商店,则在您拨打电话时,您的应用会被拒绝。如果这是一个越狱设备,你可以自己声明这个功能。

void GSEventSetBacklightLevel(float level);

您收到错误的原因是您尝试将float(标量)分配给NSNumber *。您可能希望将previousBacklightLevel更改为float。

答案 1 :(得分:2)

你可以通过jus拖放到你的xcode项目来添加私有框架来自/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework 并导入.h文件中的#import "GraphicsServices.h"标题