iphone - My iOS app loses all animation effects when running app sometimes -


i have navigationcontroller based application, , stores many images in documents directory folder ([nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]). have used sqlite.db storing images locally. image storing process following:

  • my web service returns array of images(url path)

  • i convert url image data , store converted image data documents directory folder

  • image path saved in sqlite db.

my problem when insert multiple images documents folder, animation effects stops or loses. issue saving image url data(nsdata)is time taking process (my view freezes sometimes). how solve issue?please go through following code

 //my viewcontroller class      nsstring * documentsdirectorypath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0];      nsmutablearray * mmsgarray = [[nsmutablearray alloc]init];     (int i=0; i<[imagearray count]; i++)     {         messages *msg = [[messages alloc]init];         nssting *imgeurlpath = [[imagearray objectatindex:i]objectforkey:@“imgpath”]];         nsdata * data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:[[imagearray objectatindex:i]objectforkey:@“imgpath”]]];         msg.msglocalpath =    [self saveimage:data withfilename:[self getcurrentdatetimeasnsstring] oftype:@"png" indirectory:documentsdirectorypath];         [mmsgarray addobject:msg];     }     bool msgsuccess = no;     msgsuccess = [[databasemanager getinstance]savemessage:mmsgarray];     if (msgsuccess == no) {         uialertview *alert = [[uialertview alloc]initwithtitle:@"message insertion failed" message:nil delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil];         [alert show];     } 
 //getting different imagename -(nsstring*)getcurrentdatetimeasnsstring {     nsdateformatter *format = [[nsdateformatter alloc] init];     [format setdateformat:@"yyyymmddhhmmss"];     nsdate *now = [nsdate date];     nsstring *retstr = [format stringfromdate:now];     return retstr; } //saving image documents path -(nsstring*)saveimage:(nsdata *)dataimage withfilename:(nsstring *)imagename oftype:(nsstring *)extension indirectory:(nsstring *)directorypath {      if ([[extension lowercasestring] isequaltostring:@"png"]) {          nsstring *localimgpath = [directorypath stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@.%@", imagename, @"png"]];         [dataimage writetofile:localimgpath atomically:yes];         return localimgpath;     } else if ([[extension lowercasestring] isequaltostring:@"jpg"] || [[extension lowercasestring] isequaltostring:@"jpeg"]) {         [dataimage writetofile:[directorypath stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@.%@", imagename, @"jpg"]] options:nsatomicwrite error:nil];     } else {         nslog(@"image save failed\nextension: (%@) not recognized, use (png/jpg)", extension);     }     return nil; } 

>

//databasemanager class(insert message local path sqlite db)     -(bool)savemessage:(nsmutablearray*)msgarray; {      bool insertsuccess=no;     const char *dbpath = [_databasepath utf8string];//14     sqlite3_stmt    *mstatement;     if (sqlite3_open(dbpath, &database) == sqlite_ok)     {          (int i=0;i<[msgarray count];i++)         {              messages *msg = [msgarray objectatindex:i];              nsstring *insertsql = [nsstring stringwithformat:@"insert messages(msg_local_path) values(\"%@\")",msg.msglocalpath];             const char *insert_stmt = [insertsql utf8string];              if (sqlite3_prepare_v2(database, insert_stmt,-1, &mstatement, null)!= sqlite_ok){                  insertsuccess = no;             }             else             {                 //add statement parameter query.                 if (sqlite3_step(mstatement) == sqlite_done)                  {                     nslog(@"sqlite_done");                     //  sqlite3_reset(mstatement);                     insertsuccess = yes;                 }                 else                    {                     nslog(@"sqlite_fail");                     nslog(@"insert failed: %s", sqlite3_errmsg(database));                     sqlite3_reset(mstatement);                     insertsuccess = no;                 }             }         }         sqlite3_close(database);     }     else{         insertsuccess = no;     }     return insertsuccess; } 


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -