我想從服務器中檢索包含10個圖像的文件夾,然後將該文件夾存儲在我的文檔目錄中。我做了一些代碼,但是當我運行它時,我正在獲取圖像url,而不是圖像本身。誰能幫我嗎?如何從服務器檢索一組圖像並將其存儲在iOS中的文檔目錄中?
我的代碼:
-(void)viewWillAppear:(BOOL)animated
{
NSMutableData *receivingData = [[NSMutableData alloc] init];
NSURL *url = [NSURL URLWithString:@"http://Someurl.filesCount.php"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivingData appendData:data];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error = nil;
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
printf("\n the path is :%s",[path UTF8String]);
NSString *zipPath = [path stringByAppendingPathComponent:@"filesCount.php"];
[receivingData writeToFile:zipPath options:0 error:&error];
NSString *documentsDirectoryPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"filesCount"];
NSLog(@"the path %@",documentsDirectoryPath);
}
您正確地下載圖像和保存圖像檢查此鏈接可能是小http://stackoverflow.com/questions/6821517/save-an-image-to-application-documents-folder幫助你-from-uiview-on-ios – Exploring 2013-02-19 06:32:28