Home button does not terminate program in simulator - ios

I'm new to programming and have been using this site for a while now but everything I've had to ask has been answered somewhere but I couldn't find an answer to this:
I am programming a game for the Apple AppStore using Xcode and test it on the iOS Simulator. When I "Build and Run the current Scheme" (the play button on Xcode), I can test out my game, and when I am done I can hit the "Stop the running scheme or application" (the stop button on Xcode), and of course it ends my game.
However, on the iOS Simulator, an icon for my game appears on the main screen along with apple programs such as "safari". When I click this, it enters my game and I can play it fine. However when I click the "Home button" or the "lock button" and re-enter my game, the game is continuing from where I left off; I want the game to end so when I re-enter my game it goes back to its original state.
I was wondering if anyone had a solution to this problem? Thank you in advance for your time and help!

When you hit the Home button on your device or simulator, you are simply "backgrounding" the app. That is, you are not quitting or killing the application, you are simply sending it to an 'idle' sort of state.
iOS will automatically kill/quit applications that are in the background if it needs memory, but what you are probably seeing is that you background your app (hit the Home button), and then you tap the game's icon to open it again. This will resume the game where it left off.
When you hit the square (stop) button in Xcode, you are killing/quitting your application. If you run your application from the simulator (not by hitting the play button in Xcode) and you want to quit the app entirely, hit the Home button twice or use the Command+Shift+H shortcut twice to show the app switcher, and then just drag your application's card up.
This will quit the app and make it launch from scratch when you tap the icon in the home screen again.

Return your game to the original state using this method in the AppDelegate.m:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent 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 or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
Now when you hit the home button and start the app next time it will be in the state you left it (however you want this to be).

Related

How to avoid an Apple Watch 2 App to stop running after a few seconds the screen turns into black?

I am developing an Apple Watch2 App. My app stops running after a few seconds the screen turns into black but I want my app to run on the screen even after the screen turns into black. So that the user can see my app anytime on the screen by not tapping to the app icon again.
I tried to add a timer and then an animation and also made dynamic UI changes to avoid my app to stop running but it didn't work - after a few seconds the screen turns into black, the app stops and the main watch clock screen comes into display.
I saw that it is possible to do this functionality in "Apple Workout App". When the user starts a timer, even if the screen turns into black, the app doesn't stop running so the user checks the timer anytime she/he wants. So please let me know how I can get this functionality?
Thanks,
E.
You can't control this from your app; The user selects the behaviour for their watch using the Apple Watch app on their phone. They can select "Show watch face" (the default) or "Resume Last Activity". They can also select how long the display stays on for on a tap; either 15 or 70 seconds.
Some Apple apps such as Maps, Remote and Timer can override this setting and if a fitness app has an active HealthKit workout activity then the watch will also resume the last activity on wrist raise/face tap. If your app isn't using HealthKit for a workout activity then you have to live with the behaviour the user has selected.

Detect Home button long press event in background

How can I detect Home button long press like 4 second or more event in my app which is already running in background? Is it possible to so because app is already running in background and if user long press home button of the device for 4 second or more can i detect the event in my background running app and if possible than will Apple approve this for app store?
No that is not possible. As you should know, a long press on the home button brings up Siri. Your app would interfere with that. Also, I don't believe Apple allows access to the home button event like that.
Lastly; while your app is in the background, it goes into a suspend state after a short while and no events run. The only thing the app can do is receive push notifications - unless you have been given special access to audio / gps functions from Apple themselves.
Short answer : Not possible. not at least with public method and want your app to be on Appstore.
For the Research purpose, you might want to try use private method and do your R&D with it. it might be possible.

How to resume Cordova iOS app

I am using iOS cordova-2.1.0,jqueryMobile and html5.I have added feature of phone call inside the app,when I click on 'Phone Call' link it prompts me to call or cancel.If I choose cancel button then app resumes,but if I choose call then after ending call app does not resumes its restarts.I have added UIApplicationExitsOnSuspend in appName.plist because I want to exit the app when it goes into background after pressing the home button.
the application goes to background when a call is triggered. if the application does not support suspend/resume feature just like yours "UIApplicationExitsOnSuspend", it is same as pressing HOME button for the application and hence the application does not resume.
either you have to remove this key and let the application resume or there is no other choice

Loading state of in-progress game in iOS

One of the iOS games that I really like (Fieldrunners 2) allows user to continue his/her game even after the app is killed mid-level (during game play). When the user launches the app again, it asks whether the user wants to continue the in-progress level.
How are they doing this? WHat is the easiest and smartest way (cocos2d and ios) to reload an in-progress game? It seems to me that there are so many states that need to be saved. Is it as tedious as I think it is?
EDIT:
When I say killed, I double clicked the home button and then I pressed and held on the app's icon and click the x icon.

Determine the app state on pressing home button twice with app running

I would like to know as to what the application state would be on hitting the iphone "Home" button twice with the application running.
The scenario is something like below:
My iOS app is running on the foreground
With the application running hit the home button twice to bring up the multi-tasking taskbar (obviously my app is not listed here because it's not a recently used app and is still running in the foreground)
Now press anywhere outside the taskbar (i.e in the application) and app will be back in focus again
My questions:
What state would be app be on performing above step #2? Would it enter background or still in foreground? What method would get triggered here?
On performing step #3, would the app re-enter foreground from background? Again what method would get triggered here?
Any hints/suggestions would be very helpful.
The application is about to move from active to inactive state, so it's still in-between. You should be able to use -applicationWillResignActive: in your UIApplicationDelegate.
After returning to the application, the application becomes active again thus receives a -applicationDidBecomeActive: on your UIApplicationDelegate.

Resources