改变背光水平,iPhone

Stu*_*umf 1 iphone objective-c backlight brightness

我四处寻找一种在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);
}
Run Code Online (Sandbox Code Playgroud)

我不确定是什么导致了这一点.我也不知道我的.h文件中需要什么,但我有:

NSNumber *previousBacklightLevel;
Run Code Online (Sandbox Code Playgroud)

编辑//改变了

NSNumber *previousBacklightLevel 
Run Code Online (Sandbox Code Playgroud)

float previousBacklightLevel;
Run Code Online (Sandbox Code Playgroud)

如建议的那样,这对分配错误中的不兼容类型进行了排序.

现在留下:

"_GSEventSetBacklightLevel",引自:

- MyAppViewController.o中的[MyAppViewController viewWillAppear:]

- MyAppViewController.o中的[MyAppViewController applicationWillTerminate]

符号未找到

collect2:ld返回1退出状态

不知道怎么解决这个问题!

任何帮助,将不胜感激,

//编辑

所有问题排序.感谢所有帮助过我的人.我真的很感激它,不能等到我能回答一些问题.

非常感谢,

斯图

Lou*_*arg 5

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

void GSEventSetBacklightLevel(float level);
Run Code Online (Sandbox Code Playgroud)

你得到错误的原因是因为你试图将一个浮点数(它是一个标量)赋给一个NSNumber *.您可能希望将previousBacklightLevel更改为float.