在我的应用程序中,我有UIWebView
,我想检测MP3文件是否加载(下载)。
所以我使用这个UIWebView
委托方法:
- (BOOL)webView:(UIWebView*)webview shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[[url pathExtension] lowercaseString] isEqualToString:@"mp3"]) {
[self userDidClickUrl:url];
return NO;
}
return YES;
}
问题是有时URL内部没有mp3字符串,UIWebView打开Native播放器。有可能检测到它吗?我想检测mp3文件何时开始加载。
答案 0 :(得分:1)
尝试根据您的请求检测MIMEType - 检查来自响应的MIMEType是否属于以下类型之一:
audio / mp3 || audio / mpeg3 || audio / x-mp3 ||音频/ X-MPEG3
更新:检查一下已经回答:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];
[conn start];
return YES; }
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSString *mime = [response MIMEType];
NSLog(@"%@",mime); }
完整链接: