What is the api for Calling Home Screen on iPhone - iphone

I want to trigger an event when pressing the home button. Is there any particular api for using that?
Thanks
Shawn

Use applicationWillResignActive and/or applicationWillTerminate. You have a limited amount of time to do stuff in these functions, so be quick.

Make your viewController a NSApplication delegate and the implement
- (void) applicationDidEnterBackground:(UIApplication *)application

Related

How Can I capture the event before my App is minimized?

I need to close some resources I am using when the App is minimized by clicking on Home Button.
Attention, I don't want to intercept the Home button, I know it is not allowed by Apple
thanks
Use the delegate method - (void)applicationDidEnterBackground:(UIApplication *)application which is in appdelegate class. Whenever user taps the home button, this method will be called. for more details, check apple documentation. You can use applicationWillResignActive: in case you want to detect an incoming phone call or sms as well along with app minimizing.
You want to look at the UIApplicationDelegate (reference). Specifically, applicationWillResignActive and applicationDidEnterBackground should be what you want.
From the Apple docs, this also goes into more detail with examples - App States and Multitasking.

iPhone Application Themes

I tried using a multi-value settings bundle to change the view. I would do the if statements in the applicationdidfinishloading in the application delegate. Apparently the method isn't called every time the app is loaded, and it would not work correctly.
If anyone has done this, or has any suggestions, links to tutorials. I would really appreciate it. I'm just trying to load views (nibs) based on user preference.
I think you can put your code in
- (void)applicationDidBecomeActive:(UIApplication *)application
or
- (void)applicationWillEnterForeground:(UIApplication *)application
methods also because from iOS 4.0 due to multitasking your app is just in the background state so it wont call applicationdidfinishloading method when the user presses the icon of your app again.

iphone auto lock value?

Isn't possible to retrieve auto lock value?
Or anyone know how to modify the auto lock time like those existing alarm application?
Thanks.
Yes Jason is right. you can use [application setIdleTimerDisabled:YES]; to stop the autosleep. But there is no way to access the auto lock value.
Regards,
Raxit
You can do it. you need to implement the following methods
- (void)applicationWillResignActive:(UIApplication *)application
This gets called when the phone is locked. In this method I would store the time and then impliment this method on the app delegate.
- (void)applicationDidBecomeActive:(UIApplication *)application
This function will be called when unlocking the phone. Use the time you stored when locking the time to determine how long it has been.
You can use this two methods for custom implementation of auto lock interval.

Multitasking and applicationWillEnterForeground

I am trying to have my app reload data when it is brought to the foreground via the applicationWillEnterForeground method. I can get the function to work and write to the NSLog, but I have a function that I want to be called from another class, how would I go about this?
I have tried below:
- (void)applicationWillEnterForeground:(UIApplication *)application {
//Re-run...
[MainViewController reRun];
}
Be gentle bit of a newbie...
You can register to UIApplicationDidBecomeActiveNotification, and reload your data when your receive it.

How to react to applicationWillResignActive from anywhere?

What's the code to subscribe to an event like applicationWillResignActive in any place in your iphone application?
[UPDATE]
Let me rephrase my question. I don't want to respond to this in my application delegate, but rather listen to this event from another class. Is that possible or I need to pass the event from the application delegate to the concerning class?
Looks like you are looking for this code.
- (void) applicationWillResign {
NSLog(#"About to lose focus");
}
- (void) myMethod {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationWillResign)
name:UIApplicationWillResignActiveNotification
object:NULL];
}
Take a look at the documentation for the method you're talking about:
applicationWillResignActive:
Tells the delegate that the application will become inactive. This method is optional.
- (void)applicationWillResignActive:(UIApplication *)application
[...]
Discussion
[...]
Just before it becomes inactive, the application also posts a UIApplicationWillResignActiveNotification.
Implement the method below in your application delegate:
-(void)applicationWillResignActive:(UIApplication *)application
This allows you to react when the application becomes inactive - when this is the case, it is executing but not dispatching incoming events. This happens, for example, when an overlay window pops up or when the device is locked.
Just before it becomes inactive, the application also posts a UIApplicationWillResignActiveNotification.
Your topic and question are asking slightly different things.
Your application will receive applicationWillResignActive, along with applicationWillTerminate, automatically. No subscription is necessary, just implement the function in your app.
As to how to respond, this is down to the application. While you can choose to do nothing the recommended behavior is that you cease or slow any non-critical functionality. E.g. if you were a game you would stop updating the display and/or pause the game.