suppose i am playing a game on iphone, then press home button (multi-task) and update my game from app store. after update, i press the game icon to start again, will this game start from the very beginning (like a new-installed app) or just from where i was playing?
if it starts from the beginning, everything will be fine, but if it continues to play from where i was playing, it would cause trouble (still using old game settings : old AI, old score etc.)
thank you.
Your app will completely quit, the new app will be installed, and you will launch the updated app fresh.
But! While the code and assets of you app are updated, any stored data is kept. Anything in NSUserDefaults or files in the the apps documents directly, or (obviously) any data on remote servers, wont be reset.
Apps have to be ok with being shutdown anyway. Regardless of an app update or not, the app need to be able to start from scratch and be able to set itself back up however you want it to.
So save preferences, or other user generated data, in a place that won't be wiped and the updated app will read all that back in and you can use it to set the initial state of your app however you want.
Related
When I restart the device my app is on it won't preserve the state it had once I open up the app again, it will be as if it's the first time I open, losing the session and having to re-login, how can I make my app preserve its state even through a device reboot? Like Twitter does, for example.
I'll try a bit more formal answer based on the comments you added above. I'll start by saying that the link Tim posted is something you should familiarize yourself with.
When your app is running, it's in the Foreground state. When you "exit" an app with the Home button, you're not really quitting it; you're just pushing it to the Background state. after a few seconds in background state, the OS automatically moves the app to the Suspended state. If you come back within a few minutes, your app is still in memory, so the OS just puts it back on the screen the way it was.
However, if you leave the app alone for a while and use other apps, the OS can--at any time and without warning--purge your app from memory. This is known as the "Not Running" state. Now, when the open the app again, it has to start from scratch. Obviously, the same thing happens when the device restarts--all apps are purged from memory.
The trick, then, is to save essential information about the app state whenever it enters the background state. You can use the app delegate's didEnterBackground method, or register for the UIApplicationDidEnterBackgroundNotification and invoke a method in your active view controller (or any other class, for that matter). Either way, you should save whatever state information you can.
How do you save this information? There are several strategies. For a simple app, perhaps you can register a few setting as NSUserDefaults. Or maybe you can write out a file containing whatever data the user was working on. It's really up to you.
Then, whenever the app launches, check for the presence of that saved data (however you chose to write it out), and set up the UI accordingly. To the user, it will appear as though the app never quit, which is exactly what Apple wants them to think.
I downloaded the source code located here on how to do a simple "To Do List":
http://www.icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/
What I notice is when I add anything to the list and then re-ran the simulator... whatever I added is not saved.
I installed the app on my phone and notice that the database is reseted when the Phone is turned off. The app works fine... but when the Phone is turned off (hold power button for 5 seconds) and when it turns back on... whatever I added to the To Do list is gone. It's like it's just writing to the database temporarily.
I spent several days on this and can't figure it out why it keeps getting deleted after phone is turned off. Source Code is here:
http://staging.icodeblog.com/wp-content/uploads/2008/09/todo-part-41.zip
Probably you are calling the initializedatabase everytime you run the app. Then the app copies a new copy of the database so the default data is back. Try debugging, you should only run that method if the database isn't existing...
I wrote my first iPhone App, and managed to get it into the App store. I later discovered a bug that happens on a real device but not on my emulator. I have committed a fix (changed plist to prevent app running in background), but I don't really understand why it happened.
My App allows users to record a sound-byte, however while they are recording they can use the iPhone home button to move the app to the background, and then it can keep recording forever if they don't restart the phone or the app does not crash.
My impression from everything I have read, is that this should not happen as you have to ask for background audio specifically if you want to do this, but now it appears to me that you have to ask specifically to disable it.
Could anyone explain this to me?
The iOS App lifecycle is described in Apple's iOS App Programming Guide.
The App is given the opportunity to save data and otherwise stop things that don't need to be running, before being suspended. You can request extra time doing this by using beginBackgroundTaskWithExpirationHandler:.
If you want your app to stop doing its "normal thing" when it is put into the background then you need to detect the App state transition and stop it yourself.
I am looking for a solution to save my game data so that even user delete the game and reinstall it will be still fine.
I try Tiny Tower: I deleted the game and reinstall it. Disable internet. Run the game, my game is still there.
It means Tiny Tower save the game data somewhere in the iphone.
Does anyone how to do it? Or where I can save the file in the iphone so that the file will be there even the user deleted the app?
Thanks
You datas are saved when syncing with iTunes. That's probably what happend with your test of Tiny Tower. You can store them in NSUserDefaults, or for game saves, it's better in a custom file in your documents folder. Both will be saved with the sync. But... if you delete the app from the iPhone AND from iTunes, you will loose the saves.
the way to do it is to store it in the keychain of that user
In the home page of my iphone app, there is a button added. When that button is clicked some other iphone app needs to be opened in a new viewcontroller (with out closing the parent app).There will be a back button on this view controller. When the back button is clicked, the new viewcontroller which is showing the another app needs to be closed and our parent app's home page needs to be shown.
Please give me some ideas on how to do this. I googled for this i didnt get any solutions.
Thanks,
Raja.
-- the following applies to iOS versions previous than 4.0 :)
Actually, there can be only one iPhone application running at once (with exceptions of Safari, Phone and some other system applications). The iPhone Human Interface Guidelines say so:
Only one iPhone application can run at a time, and third-party applications never run in the background. This means that when users switch to another application, answer the phone, or check their email, the application they were using quits.
However, if you only need to e.g. show a webpage, you can do it using UIWebView
Also, if you need to open another application, you should use URLs as pointed by Steve Harrison. This will, however, close your application. The recommended behavior in this case is to remember your application state and restore it when the application is run again, as Nithin writes.
According to apples documentation, they are not allowing any applications to be run in the background, except system generated ones. So you will be unable to do the thing you are going to implement. However, there is one thing that can make the same result.
You told that you are calling other application to run on a button click. Before initiating that application, save the current state of your application, may be using sqlite3 or core-data, and then open the other one. While returning back, load the pre-saved data from the database or wherever you have stored it. Every time you start the application, you check for the persisted data, if exists, load it or otherwise load your basic view
I don't think that you can run other iPhone apps within your own one. It doesn't make sense. You can open another iPhone app via a URL (see here and here), but this will close your app.
Like it has been stated: running two apps is not allowed by apple. You can however implement this apps features into you're app and have both get and save data to the same server...
Or like Nithin said: this functionality is available on JB iphones. Look into "backgrounder" for implementing one solution for normal users and one for thouse that has jailbroken.