Posted By

saturngod on 09/17/10


Tagged

downloadsavehttp


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
bobbym245
cnathan


Download and Save File iPhone SDK


 / Published in: Objective C
 

URL: http://stackoverflow.com/questions/2308159/download-a-file-iphone-sdk

  1. NSError *err = [[[NSError alloc] init] autorelease];
  2. NSString *url = [[NSString stringWithFormat:@"http://myurl.com/mypage"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  3. NSString *myTxtFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:&err];
  4. if(err.code != 0) {
  5. //HANDLE ERROR HERE
  6. }
  7.  
  8. //save
  9. [[NSUserDefaults standardUserDefaults] setObject:myTxtFile forKey:@"MyFile"];
  10.  
  11. //retrive
  12. NSString *myTxtFile = [[NSUserDefaults standardUserDefaults] stringForKey:@"MyFile"];

Report this snippet  

You need to login to post a comment.