ios - Opening large son file at app launch forcing long start time -
i creating game made of different game boards stored dictionaries, in array, in json file. json file quite large, on 3,000 objects in array, 23mb in size. way loading file @ moment in didfinishlaunchingwithoptions in appdelegate implementation file so:
nsstring * filepath =[[nsbundle mainbundle] pathforresource:@"words" oftype:@"json"]; nserror * error; nsstring* filecontents =[nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:&error]; if(error) { nslog(@"error reading file: %@",error.localizeddescription); } nsdictionary *data = (nsdictionary *)[nsjsonserialization jsonobjectwithdata:[filecontents datausingencoding:nsutf8stringencoding] options:0 error:null]; wordsarray = [[nsmutablearray alloc]initwitharray:[data objectforkey:@"results"]]; then can retrieve array anywhere in app calling:
nsarray *wordsarray = appdelegate.wordsarray; it works great except fact app takes on 15 seconds load on iphone 4 device way long , understand app can rejected loading times long.
can suggest better way go this,
thanks
as suggested yedidya, may want show interesting stuff keep user engaged.
on top of that, important thing to:
- keep ui responsive
- do loading of file / network resource on background thread. there ample code samples showing same. use 1 of
performselectoronbackgroundordispatch_async(some_global_queue)perform background task. - once done, come main screen / game ui using
performselectoronmainthreadordispatch_asynch(dispatch_get_main_queue).
here gist:
//start busy cursor here dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{ // read json file here dispatch_async(dispatch_get_main_queue(), ^{ //stop busy cursor //perform ui update here });
Comments
Post a Comment