Monday, 15 April 2013

xcode - Updating Plist file via download iOS -



xcode - Updating Plist file via download iOS -

i've got quiz app on apple app store. questions stored in plist file. i'm looking find way update plist file via downloading new version , not having submit update every time have new questions add

does know of decent tutorial may help me?

many thanks.

i'm not sure tutorials, steps accomplish describe pretty simple:

create url request remote data parse returned data write parsed info new local plist

eg:

// create nsurl info nsstring *datapath = @"www.mydata.com/path"; nsurl *dataurl = [nsurl urlwithstring:datapath]; // create asycnhronous request along block executed when finish [nsurlconnection sendasynchronousrequest:[[nsurlrequest alloc] initwithurl:dataurl] queue:[[nsoperationqueue alloc] init] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) { if (error) { nslog(@"%@", error.localizeddescription); // handle request error } else { // have data, need serialize it's usable nserror *serializationerror; nsdictionary *serializeddictionary = [nsjsonserialization jsonobjectwithdata:data options:0 error:&serializationerror]; if (serializationerror) { nslog(@"%@", serializationerror.localizeddescription); // handle serialization error } else { // have serialized nsdictionary, want write // first create path write to, eg. uers documents directory nsurl *documentsdirectory = [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastobject]; // write bool success = [serializeddictionary writetofile:documentsdirectory.path atomically:yes]; if (!success) { nslog(@"error writing file"); } } } }];

note: may want think storing info in remote database parse. way can query new questions , download you're not using unnecessary bandwidth. may want consider using core data maintain local info rather writing plist. main advantage beingness don't have serialise entire plist memory utilize - can query particular questions need.

hope helps.

ios xcode

No comments:

Post a Comment