2012-09-21 192 views
1

在文本框中,我输入一个url并将其下载到特定路径并存储该下载文件我必须给出该文件的具体位置和文件名。这是行得通的,但是当我下载任何其他格式(如.MP4,.AVI)将存储为MP3播放下载文件并保存到内存

NSString * URL =Textbox.text; 
dest_path=[NSHomeDirectory() stringByAppending:@"/Documents/file.mp3"]; 
//to download url and save to specific path 
download=[Downloader Download:URL withTargetPath:dest_path withDelagate:self]; 

我想,只要我下载应该从那里格式。就像被保存。如果我下载的MP4文件。它应该是与.MP4保存format.please提出了一些代码..

+0

使用Asynchronus下载。 – Krunal

回答

0
NSURL *url=[NSURL URLWithString:@"/Documents/file.mp3"]; 



    NSURLRequest *req=[NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:120]; 

    NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES]; 

    if(con){ 
     receivedData = [NSMutableData data] ; 
    } else { 

    } 

用途:

NSURLConnectionDataDelegate,NSURLConnectionDelegate 

方法

,如:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {} 
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d{} 
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {} 
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {} 
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {}