我想在iOS应用中显示下载进度。我实现了方法
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
和-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
但他们没有被召唤。我如何设法让他们被召唤?我应该建立连接吗?我正在做,没有任何反应。
由于
以下是一些代码:
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"Data");
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Response");
}
- (void) playAudiotWithURL:(NSString *)url
{
plistManager = [[GVPlistPersistence alloc] init];
arrayConfigs = [plistManager plistFromDocumentsFolderNamed:@"Configs.plist"];
NSError *error;
nerdcast = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
audioPlayer = [[AVAudioPlayer alloc] initWithData:nerdcast error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.delegate = self;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
从另一个类调用 PlayAudioFromURL