0
私のアプリケーションを介してインターネットからmp3ファイルをダウンロードする必要があり、NSURLConnectionと接続要求を使用するための解決策が見つかりました。ここに私のコード(他のよくある質問からコード)NSURLConnection非同期ダウンロードデータがiPhoneのローカルファイルに保存されていますか?
は、私はiPhoneの私のローカルファイルには、この応答データmp3ファイルを保存する方法- (IBAction)downloadData:(id)sender
{
NSURL *myURL = [NSURL URLWithString:@"http://www.example.org/mp3song"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[responseData release];
[connection release];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received %d bytes of data",[responseData
length]);
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
}
のですか?