下载的文件传输失败

时间:2012-05-07 11:44:50

标签: objective-c ios nsdata

从服务器成功下载文件后,我试图将其保存到文档目录中的某个文件中,但是,我总是失败转移,不知道出了什么问题。

-(IBAction)downloadAndPlay:(id)sender{

        NSString *fileUrlPath=[host stringByAppendingString:rowContent];  

        NSURL *url = [NSURL URLWithString:fileUrlPath];
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
        [request setDelegate:self];
        [request startAsynchronous];

}

- (void)requestFinished:(ASIHTTPRequest *)request
{

    // Use when fetching binary data
    NSData *responseData = [request responseData];
    NSLog(@"Succeeded");//I got successfully the response data
    BOOL transferStatus=[responseData writeToFile:path atomically:YES];
    if (transferStatus==YES) {
        NSLog(@"Transfer succeeded");
    }else NSLog(@"Transfer failed");//I got always Transfer failed

}

注意:路径字符串是这样的:

NSLog(@"%@",path);//  /Users/MacName/Library/Application Support/iPhone Simulator/5.0/Applications/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents/AudioAndVideosFiles

该文件是mp3或mp4文件。

先谢谢你的帮助。

0 个答案:

没有答案