SQLite resets when Project is Re-ran in Simulator - iphone

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

Related

App crashes when network changes

I have to fix some bugs in an app somebody else developed. I have not worked on iOS before.
The iOS app sends some data out every 15 seconds, this works fine. I can click the home button and go back into the app, works fine too.
Now the problem only comes when there is a change in the network, lets say I activate Flightmode.
When I go back into the app it crashes because of a NSRangeException. The problem is I can not get any Debug output out or anything, even if I put debug statements around all the places where this Exception can happen.
Could somebody give me a tip? How can a change in network have such a effect?

logs on second run of an ios application in the simulator

I have a question which seems like it should be a fairly common occurrence. I am trying to test code which only runs the first time an ios application is installed. While in principle this is very easy, I'm having trouble with it behaving properly the second time the app runs (note, this is not crash related).
I have been force running the app for a second time using the "Application does not run in background" flag in the plist, and then just hitting the home button. This works great, except i stop getting log data after the first run.
Does anyone know how to test for this situation in a way where you can continue seeing the log information after the app closes? For example, if there is a way to attach the xcode logger to the new process id? Or just another way to force an app reboot without losing the logging feature?
Thanks in advance!
Use the debugger menu:
Product>Attach To Process
(Results may vary with different versions of Xcode).
Also, you might need to insert a sleep at the very start of your launch to catch the very early log messages.
EDIT: If you're on a device then you can use the Device Organizer (cmd+shift+2) to watch all logs on a device.

Will app start run from begining after an update?

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.

Core Data lightweight migration crash

I updating my database with a lightweight migration. If I do the update on my device through xcode in debug mode everything runs fine. If I load the app through iTunes as a archive file it will crash before loading the rootViewController. This only happens with my large test database >100mb. I don't get anything useful in the crash log and am not sure what to do with this.
His is the only relevant line I can find in the crash log.
Unknown thread crashed with unknown flavor: 5, state_count: 1
Normally this would be reflected in the crash report (It would say something about failing to launch in time) but iOS devices expect you to get a view on the screen (or for ApplicationDidFinishLaunching to finish, I'm not sure exactly what it looks for) in a certain amount of time or it just gives up and closes the app. If you are doing a significant amount of work you'll want to get some kind of screen up before you start that work. Unfortunately this doesn't happen in a debug environment so it's a pain to test.

iOS 4 Core Data... any changes with multitasking?

I have a question,
i carefully went through and thoroughly understood the tutorial for iOS Core Data.
The issue was that when i coded everything and run on iOS 4 with multitasking.. the program crashed when i re-opened it (kill task from fast app switching and relaunch)
Then i went curious and recode it on iPad (since it hasn't support multitasking) and it works fine...
I went to explore abit, and some says that the fast app switching kill app is like the OSX kill app and there is applicationTerminate method in the delegate file which maybe need some changes (based on the comment).
Could someone enlighten me on that issue? Is there anything additional that i need to do in order to have Core Data to support the Multitasking feature..
Thank you!
Update
Ok but the thing i am not getting is that.. once i killed the app.. go Fast App Switch, kill it... and when i re-run the app.. it crashed.. Do i need to add some stuff to the multitasking methods? It crashes even if its a basic app with 1 button... What are the states that i have to save?
Update
The app just freeze on its own
Update
Alright my bad, trying my best, for the one button app... I sticked a button in there, and for each click, it prints an NSLog and a label. When i build and run it, it works fine, clicking it prints them normally. After going to background and close the app.. it sends SIGKILL Then when i relaunch the app, it no longer prints to NSLog and crash there 0x98a450f0 <+0000> mov $0xffffffe1,%eax 0x98a450f5 <+0005> call 0x98a453d8 <_sysenter_trap> 0x98a450fa <+0010> ret 0x98a450fb <+0011> nop
Update
However when i open the Iphone simulator and run the program directly... without building it from xcode.. It works just fine and it was able to print that value. Same is true for the Core Data.. if i just run it from the Simulator. Kill it and re-run, it works fine.. Not sure what's going on
With iOS 4.0, your app may not receive a -applicationWillTerminate call. It may only receive a call to go into the background and then be killed.
When you get the call to go into the background you should dump as much memory as possible to avoid being killed, that includes saving your context and perhaps calling reset on the context to get it to drop its cache.
Other than that, no changes need to be made.
What crash are you seeing, a stack trace would be helpful to explore this further.
Update
Again What crash are you seeing?
Update
Freezes where? Where does it stop when you look at it in Shark or the debugger? You are not giving me a lot of information to go on here :)