suse
suse

Reputation: 10563

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 contents of NSData into a file.

Upvotes: 1

Views: 499

Answers (2)

Muhammed Ayaz
Muhammed Ayaz

Reputation: 43

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];

Upvotes: 1

Kyle
Kyle

Reputation: 443

Take a look at the NSData writeToFile:atomically: method. Just pass in the filename and it will do it for you.

Upvotes: 3

Related Questions