ios - Save file with bulk action in to document directory -


i trying save files in document directory, in bulk action , using method:

nsurl *url = [nsurl urlwithstring:@"http://www.mywebsite.com/storage/image.png"]; nsdata *data = [nsdata datawithcontentsofurl:url]; nsstring *documentspath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes)[0]; nsstring *downloadfolder = [documentspath stringbyappendingpathcomponent:@"image.png"]; [data writetofile:downloadfolder atomically:true]; 

this working well, single file, copy in same times files in storage folder in document directory.

does know how can that?

thanks.

if want save image bulk in document directory.

you can use nsuserdefaults hold last image index, , increment index 1 when store new image, try this.

nsurl *url = [nsurl urlwithstring:@"http://www.mywebsite.com/storage/image.png"]; nsdata *data = [nsdata datawithcontentsofurl:url]; nsstring *documentspath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes)[0]; nsstring *filepath;  id index = [[nsuserdefaults standarduserdefaults] objectforkey:@"imageindex"];  if(index){     int = [((nsnumber *) index) intvalue];     ++;     [[nsuserdefaults standarduserdefaults] setobject:[nsnumber numberwithint:i] forkey:@"imageindex"];     filepath = [documentspath stringbyappendingpathcomponent:[nsstring stringwithformat:@"image_%d.png",i]];  }else{     [[nsuserdefaults standarduserdefaults] setobject:[nsnumber numberwithint:0] forkey:@"imageindex"];     filepath = [documentspath stringbyappendingpathcomponent:@"image_0.png"]; }  [data writetofile:filepath atomically:true]; 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -