0
私は、ファイルをダウンロードする際、私は、接続を停止したいので、私が作成した、これは私が使用したコードである 、サーバからデータを受信するnsurlconnectionを停止する方法は?
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response {
filename = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"Ep1.mp4";
[[NSFileManager defaultManager] createFileAtPath:filename contents:nil attributes:nil];
file =[NSFileHandle fileHandleForUpdatingAtPath:filename] ;
if (file) {
[file seekToEndOfFile];
}}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if (file) {
[file seekToEndOfFile];
} [file writeData:data]; }
- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
[file closeFile];
}
-(void)downloadFile{
targetURL = [NSURL URLWithString:@"http://some url "];
DownloadRequest = [NSURLRequest requestWithURL:targetURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:50.0];
DownloadConnection = [[NSURLConnection alloc] initWithRequest:DownloadRequest delegate:self];
if (DownloadConnection) {
receivedData = [NSMutableData data];
}
}
をnsfileハンドル付きURL接続を使用していますボタン --->
- (void)buttonPressed:(id)sender
{
DownloadConnection = [[NSURLConnection alloc] initWithRequest: DownloadRequest delegate:self];
[ DownloadConnection cancel];
}
が、動作しません、データがまだ受信、私は何かを理解して欠場しましたか? または何ができますか?
参照[この](http://stackoverflow.com/a/7229304/845115) –
ありがとう〜私は "自己"が恋しい.... – cmin