Data Not Storing Correctly On Device


#1

I have found that archiving the data during the applicationDidEnterBackground: state, does not properly archive the data on a device.

Yes, it stores it if you press the home button, then go back into the app, however if you remove the app from the multitasking menu, then go and open the app again, the data has gone.

I have now had to implement the saveChanges: method in to the applicationWillTerminate: method.

Why is this the case on a physical device, whereas it does not happen on the simulator?

Nick
http://myfirstiphoneapp.co.uk


#2

Has no one else had this same problem?


#3

Did you make sure that the data get to its destination in applicationDidEnterBackground:?
If you look at the NSUserDefaults class, you will see that it has a synchronize method; maybe you need to do something similar.


#4

My query is to why “I believe” we have not been shown the proper method for fully archiving the data in this chapter.

As I mentioned, on the simulator, the data is archived properly, however on a physical device I have had to invoke the saveChanges: method inside the applicationWillTerminate: method.

As NSUserDefaults are not explained until Chapter 18, surely if this is what we need to do should be explained here, or if not, the correct method(s) for archiving should be explained.

ibex: Have you been using a physical device to test these applications, or are you only using the simulator? If you have used a device, have you found the same problem as myself?

Nick


#5

[quote]
ibex: Have you been using a physical device to test these applications, or are you only using the simulator? If you have used a device, have you found the same problem as myself?[/quote]
I use both. I have also experienced similar problems in the past.
Also the differences between the simulator and the physical devices are not insignificant. It is good that you are testing your apps on the intended devices.


#6

Isn’t it just that the simulator is normally terminated through XCode with a “kill” command, whereas on a device, you virtually never kill an app. Certainly, it isn’t possible on the iPhone to kill the currently-active app (you have to put the app into the background before you can kill it).

So, they point out that there are differences between the Sim and the Device; good to keep that in mind always.

And then at the end of Ch.14 the book goes into some length about the various state transitions… and the various methods that would exist for you to implement different things on various transitions.