Screen Off event or property on iPhone - iphone

Is there a way to determine if the screen has been shut off via the top Power button?
I just need to know if the screen has been somehow set to off to kill a loop that updates location.
Thanks

Your Application delegate will receive a applicationWillResignActive: message just before the screen is locked (or when the phone rings or another window pops up). This is an excellent time to kill any idle-time processes. After re-activating, you'll receive an applicationDidBecomeActive: message, in which you can restart all this stuff.

Related

Does OnNavigatedTo get called when you turn on the screen and the app comes to life?

I'm dealing with a strange situation I want to debug in my Windows Phone 8.1 app, and I'm not sure in which moments OnNavigatedTo is called.
Obviously, it gets called (and I've checked tracing it with the debugger) when you navigate to the view normally.
My doubt arises in other point I want to check, let's call it "You wake up your application and the screen was shut off".
My question is: When you turn on the screen, and you swype the screen protector away, is "OnNavigatedTo" function called or not?
According to some manuals I've read somewhere else, it should.
According to my Debug.Writeline traces, it seems it doesn't.
I need to check some condition and execute some code before/when the view appears, and I'm unable to do it properly.
PS: Does it exist some other alternative event I should use to deal with "This view is becoming visible/focused after you turn the screen on" situation instead of "OnNavigatedTo" ?
Thanks in advance.
In Windows Phone 8.1 Runtime (Store apps) OnNavigatedTo is called only during navigation. It's not called after resuming from suspension - you can read a reference here at MSDN:
before Suspending event, the OnNavigatedFrom event is being called, but when you Resume, the OnNavigatedTo is not called
In your case when you lock the screen, the app is suspended, after you resume OnNavigatedTo is not called. If you look for some events which may be called - take a look at Window.Activated and Window.VisibilityChanged events.
The other case is that when you debug your app, your app won't be suspended, you will need to test it via Lifecycle events tab.

How to detect whether user didEnterBackground because of phone call or click on home button?

We have a multiplayer game and sometimes user quit the game so we would like to know how did user quit the game. Can we use didEnterBackground for that?
We would like to know whether user quit the game by clicking exit button, or by incoming call, or by home button to exit.
When you press home button your application is sent to background and applicationDidEnterBackground will get call first and if it is by call, sms then applicationWillResignActive will get call first.
This is not perfect answer of your question but this might help you in some.
in the appDelegate.m File u have this function:
- (void)applicationDidEnterBackground:(UIApplication *)application
write the code you want in it. (saving data or anything)
First of all, the user interface guidelines forbid quitting an app programmatically and based on what I have read, apps the provide an exit button will be rejected.
If by 'quit the game' you mean something along the lines of 'terminated gameplay', then that should not be a problem.
Also note that pressing the home button does not exit the app. It simply sends it to the background. There does not appear to be any facility to detect why the app left the foreground, which probably means that Apple wants your app to handle all such cases in the same way: by saving state and being prepared to restart where execution left off. Note that an application in the background can be terminated at any time, hence the need to save state.
The answer to your question therefore would seem to be: don't do that.

An event should invoke a method while the app is on Background-iphone

I need to invoke a method each time an event is occurred even if the application is in the background.
In my case -each time I get a picture from the server I want to present it,
and if the application is in the background I want it to reEnter the foreground and present the picture.
Is it possible? if not, what is the nearest alternative?
Thanks,
Asaf
i thnk this is not possible, but use notifications to do this that application will become active when it receive notification.
further see these threads
iPhone OS 4.0.x - transition from background to foreground
How to bring app to foreground programmatically

How to handle the phone call while running the application in iphone

I am doing with a paint application. while drawing any picture if I got any phone call, the application is getting quit and reopens immediately after end of the call. But my requirement is I should able to draw the picture while I am in incoming call.
Any one can Please help me out
When a phone call comes in, and the user picks it up, they will always leave the current app and the phone app will start. I don't think you can change this behaviour.
While the user is in the phone call, though, they can change to another app simply by pressing the home button and starting another app from the home screen, or by double-pressing the home button and switching to another app, including yours.
In that case there will be a thin view below the status bar indicating that they're in a call, so you have to make sure your app resizes properly to make space for that.
This is default from apple that any application go inactive if incoming call is in active.We cannot change this.
Use the below Appdelegate method:
(void)applicationWillResignActive:(UIApplication *)application
This delegate will call when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call
)
To Restart any tasks that were paused (or not yet started) while the application was inactive. For this use the below appDelegate
(void)applicationDidBecomeActive:(UIApplication *)application
For more visit app multitaking
Hope, this will help you..

Iphone Calendar Application

i try to retrieve Calendar events between two dates. After that I try to delete all events. this program is working fine. The Events deleting process will take few second/minute based on number of events.
When device goes to sleep this application will work in background as usual. After coming to normal state(wake up) my application will exit. But, i did over come this problem, disable idle time.
But this same problem repeating when i press sleep/wake up button on the top of iPhone. How to over come this problem. What happens in my application, when changing state, any memory problem or any other...
When the sleep/wake button is pressed, your application is sent to the background/changes mode to inactive. Check UIApplicationDelegate documentation applicationWillResignActive: and applicationDidEnterBackground:. When this happens there are restrictions about your application doing background operations, which are described within the documentation.