开发者

How to retrieve data from server and save into a file in [Objective-C] iPhone programming?

开发者 https://www.devze.com 2022-12-24 04:35 出处:网络
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 f

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

精彩评论

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