Загрузка текстового файла - iOS - PullRequest
0 голосов
/ 01 апреля 2012

Я пытался использовать ASIHTTPRequest для загрузки на сервер.Но я, кажется, не понимаю.Ниже приведен код реализации.Любое предложение?

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

//make a file name to write the data to using the documents directory:

NSString *fileName = [NSString stringWithFormat:@"%@/LightMode.txt", 

                      documentsDirectory];

//create content - four lines of text

NSString *content = @"studyMode";

//save content to the documents directory

[content writeToFile:fileName

          atomically:NO

            encoding:NSStringEncodingConversionAllowLossy 

               error:nil];


NSURL *url = [NSURL URLWithString:@"http://spider90.dyndns.org:8080/sid/"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

NSData *postData = [NSData dataWithContentsOfURL:@"%@/LightMode.txt"];

[request addData:postData withFileName:@"LightMode.txt" andContentType:@"txt" forKey:@"text"];

[request setDelegate:self];

[request startSynchronous];
...