开发者

iphone standby button

Is there an event when the user presses the standby button?

I can disable "auto standby" (autolock) - which I do because my app is some kind of a routing application.

But how about the standby button?

The 开发者_开发知识库problem - if the iPhone goes standby the GPS is turned off. So my app thinks it has a GPS problem. This is in fact wrong - it's only standby which means a different handling should be done as if I do it when GPS problems occure in "running mode" (the users sees the app).

I couldn't find an event for this situation (neither going standby - nor awaiking from it)


You have to listen to these 2 notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appLostFocus:) name:UIApplicationWillResignActiveNotification object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appGotFocus:) name:UIApplicationDidBecomeActiveNotification object:[UIApplication sharedApplication]];

and handle them appropriately:

- (void)appLostFocus:(NSNotification*)notification
{
    NSLog(@"app lost focus");
}

- (void)appGotFocus:(NSNotification*)notification
{
    NSLog(@"app got focus");
}

To disable auto-standby just implement this in your main app delegate:

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

//...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜