开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜