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 格式保存。请建议一些代码..

4

1 回答 1

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 {}
于 2012-10-01T06:39:19.310 回答