How to retrieve data from server and save into a file in [Objective-C] iPhone programming?
I've saved the contents of server into a NSData. How do I copy the co开发者_StackOverflow社区ntents of NSData into a file.
Take a look at the NSData writeToFile:atomically: method. Just pass in the filename and it will do it for you.
NSString *imagelist = Data;
NSData *yourimageFileData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imagelist]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *yourFilePath = [documentsDirectory stringByAppendingPathComponent:reString];
[yourimageFileData writeToFile:yourFilePath atomically:YES];
精彩评论