Loading state of in-progress game in iOS - 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.

Related

Killing an iOS app programmatically

I have an app when a specific action fires I close the app and ask the user to reopen it again.
The problem is when the app executes exit(0) the app stays in the apps stack (when I click the home button twice). I want it to be killed completely so that viewDidLoad() will be executed again when the app opens.
You cannot terminate an app on it's own.
From Apple's Human User Guidelines...
Don’t Quit Programmatically
Never quit an iOS application programmatically because people tend to
interpret this as a crash. However, if external circumstances prevent
your application from functioning as intended, you need to tell your
users about the situation and explain what they can do about it.
Depending on how severe the application malfunction is, you have two
choices.
Display an attractive screen that describes the problem and suggests a
correction. A screen provides feedback that reassures users that
there’s nothing wrong with your application. It puts users in control,
letting them decide whether they want to take corrective action and
continue using your application or press the Home button and open a
different application
If only some of your application's features are not working, display
either a screen or an alert when people activate the feature. Display
the alert only when people try to access the feature that isn’t
functioning.
Have a look at this answer: https://stackoverflow.com/a/8491688/742298

Objective C - Detect if finger is held on screen at app startup

I'd like to perform an action when the user has their finger held on the screen when my app startups.
To give an example: When the App launches and the launch screen is showing up, the user has a finger on the screen as long as the first ViewController appears. When the first ViewController gets into the viewDidAppear() function, I want to detect, that the users finger is on the screen and perform an action, like f.ex. jumping straight into the lastest received email. Basically this is supposed to be a kind of shortcut to an main action.
Is there any method to detect an already laying finger on the screen? To be exactly I'd like to check for the tap in viewDidAppear()
Unless the nature of Time has changed since the last time I checked, your app cannot detect what the user was doing before the app launched. The app, ex hypothesi, was not running at that time. And the mere presence of a finger on the screen during app launch will not generate a touch event that the app can detect.
The system can detect it, however, since is running before your app launches. That is why Apple added force-touch Shortcuts (for appropriate hardware). The only way you can do what you're asking is to rely on that API. Hardware that lacks this feature will simply have to do without this feature.
(After all, this is how Apple makes money: by trying to make users jealous of hardware they don't have, so that they buy new hardware. You would want to rob Apple of its income by reading this feature backwards onto old hardware, even if you could, now would you?)

Any way to re-show Game Center login view? (Xcode)

My app attempts to log the player in when it finishes loading, like good little apps should (so says Apple). But if the player chooses to cancel the initial log-in, I wanted the app to re-attempt to authenticate the player if the player taps the leaderboard button in the game. (otherwise, of course, the button couldn't do anything if the player is not authenticated)
Unfortunately, after some research I discovered that Apple does not seem to allow an app try again to re-authenticate the player after the player cancels the first time, until the player exits and re-enters the game. (If the player cancels three or so times, Apple goes aggro and disables Game Center from the app on that device entirely. Even logging into Game Center from the stand alone app won't help after that point.)
Is there any way around this so that my app can attempt the authentication both when the app loads, and any time the player taps leaderboard button while not logged in? Or do I just have to have my leaderboard button display a message when not authenticated saying that Apple's being dumb and overprotective and not letting my app respond the way it should? (Perhaps not quite in those words...)
I've used an alternative approach that might solve your requirement. When they tap on the leaderboard, check the Game Center connection state.
If it is not GCPConnectionStateEnabledFully then throw up an alert like this "Error connecting to Game Center. Please make sure you are signed into Game Center and check your internet connection". Then inevitably they will leave your app to check and when they return the Login prompt will appear a few seconds after they return to the app.
Testing note: When you are testing these scenarios you might cancel the login prompt 3 times. If you do that it will stop prompting you altogether and you need to reset all settings in the Settings app. I remember this being really frustrating.

Home button does not terminate program in simulator

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).

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.

Resources