Not all NSUserDefaults are restored on app relaunch - ios

I am converting 2 custom lists into a json string and storing it the NSUserDefaults. Something like so:-
NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Take(50)), "StationList1");
NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Skip(50).Take(50)), "StationList2");
If I try and retrieve them immediately after saving them like below I get the saved values:-
savedStationList1 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList1");
savedStationList2 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList2");
But the issue is if I restart the app, and try to get the above values in another part of the code, I only get the value for:-
savedStationList2 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList2");
and the value for below is always null :-
savedStationList1 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList1");
I do not override these values anywhere within the app. Is there a way I can solve this?
Any help is appreciated

Although natively the iOS system does store data added through 'userdefaults' it may not do this instantly. I would suggest adding the following line:
NSUserDefaults.StandardUserDefaults.Synchronise();
After you store data to standard user defaults run the synchronise and test that you can extract the data, you should find that this will now work correctly for you.

Related

SetValue in Swift from Firebase removes old value's

In the documentation it says that I should use this code to set new value's:
self.ref.child("users").child(user.uid).setValue(["username": username])
This way, I can set an username. However, if I want to add another value later on, like XP points, I use the following line of code:
var XPPoints = 1
self.ref.child("users").child(user.uid).setValue(["XPPoints": XPPoints])
This, however, deletes the username value, or any other value that was stored before. It replaces all value's.
I tried also the second thing the docs are saying at: https://firebase.google.com/docs/database/ios/read-and-write#basic_write which is this line of code:
self.ref.child("users/(user.uid)/username").setValue(username)
This will crash my app instantly when starting up. My question is: How can I add data, and not replacing the old value's?
Edit:
Fixed it by changing the code to:
self.ref.child("users/\(user.uid)/username").setValue(username)
Your solution shouldn't fix the problem you are having. You need to use updateChildValues instead of setValue. This adds the values instead of overwriting everything in the referenced node.

Storing gps location data in Parse

I want to build an app like RunKeeper, as detailed in this tutorial. But I want to save the data in Parse cloud.
I will have a user object, and a user can have multiple runs. I am not sure how to save the gps locations for each run. Since there can be hundreds of locations for each run. Can someone please explain what would be the best/efficient way to save the locations.
Thanks.
Save lat/long pairs as double precision floating point values. That's all there is to it.
To solve your problem,
In the user class I would add an array of _runId.
After I would create a class Run with the specific property. So when the user do a run you append the id in the _runId array of the user class.
In the Run class, you could have a property like: location. It should also be an array (_location). So when the user is running you can append to the location array the location of the user for the specific run.
After that you would be able to get all the location of the user with the runId.
Hope this help!
What if you save all geo data to a JSON file, let's say that each JSON file will be a run, then save the JSON files into your Parse.com.
Good luck.

How to push my Records into SC.ArrayController content?

I am trying to get my sample data (records created from fixtures) into my SC.ListView. I know the records are built properly because I am able to get particular data by finding it by its primaryKey.
The SC.ListView is pulling its content via contentBinding: 'MyApp.thisController.arrangedObjects' from this SC.ArrayController:
MyApp.thisController = SC.ArrayController.create(SC.SelectionSupport, {
allowsMultipleSelection: NO,
content: MyApp.store.find(MyApp.MyRecordType)
});
To init the store I use the function from the official guide:
store: SC.Store.create().from(SC.Record.fixtures)
How do I set my content property in the controller right to import the SC.RecordArray?
this will only work if your store is created before your controller. Try doing
MyApp.thisController.set('content', MyApp.store.find(....));
after the app loads, in the console. If that works, you need to query the store after your app initializes.
my problem was that the store was generated AFTER the controller tried to set the content, which is very confusing because with the following code from another tutorial it is working fine.
store: SC.Store.create().from(SC.FixturesDataSource.create({
simulateRemoteResponse: YES,
latency: 250
}))
Anyone knows to tell me why the store creation in the question text fails to generate before?

WP7 tombstoning Memory Save

So for my windows phone 7 app, I am trying to save the user input after they 'tombstone' my app when I first debugged the app I got a KeyNotFoundException, but after I entered some data into my textbox and tombstoned my app the I didn't get a KeyNotFoundException. Can someone please help me with this problem?
KeyNotFoundException means that you are trying to get some data from data collection by key, and that key/value pair does not exist:
http://msdn.microsoft.com/en-us/library/system.collections.generic.keynotfoundexception.aspx
Before trying to access the date using key, first check if that key even exists using ContainsKey method:
http://msdn.microsoft.com/en-us/library/kw5aaea4

iOS WebApp - Remember Device for saves

I've got a webapp running in fullscreen that interacts with a database via ajax.
Is there a way i can get a "signature" or "id" of a device to store for each device???
Basically I've got a "saved items" option, and they will be saved to a unique id. I cant use IP Address coz of multiple devices or if you use the 3G service. Any other ideas? (dont want user authentication).
Could I save an array in the manifest file and access that?
Thanks
I solved this issue by using html5's local storage.
i used
var salt=Math.floor(Math.random()*10000); //makes random salt
var randomId=Math.floor(Math.random()*20000); //makes another random number
randomId = salt+(salt*randomId); //makes the id even more random to avoid dupes
localStorange.setItem('deviceId',randomId); //sets a local variable that can be accessed by localStorage.getItem('deviceId'); and cross-refrenced with a $.get from a database to load the saves.
$.post("saveDeviceId.php?id="+randomId); //saves the new id to the database
this is how i resolved it anyway, unless anybody has a more efficient way?

Resources