場景
在下面回調(diào)函數(shù)中下斷點,當(dāng)前使用 UIWebview
加載 mp4
格式視頻時叼风,會捕捉到異常。
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
...
}
打印錯誤明細
(lldb) po error
Error Domain=WebKitErrorDomain Code=204 "Plug-in handled load"
UserInfo={
NSErrorFailingURLStringKey=file:///~/Library/Developer/CoreSimulator/Devices/5563EC11-037A-4FD8-8815-8B4867
Error Domain=WebKitErrorDomain
Code=204 "Plug-in handled load"
UserInfo={
NSErrorFailingURLStringKey=file:///~/Documents/263-E99658601-uat/CoursePacages/PackageCourse/252.mp4,
NSErrorFailingURLKey=file:///~/Documents/263-E99658601-uat/CoursePacages/PackageCourse/252.mp4,
WebKitErrorMIMETypeKey=video/mp4,
NSLocalizedDescription=Plug-in handled load
}
05BA58~/Documents/263-E99658601-uat/CoursePacages/PackageCourse/252.mp4,
NSErrorFailingURLKey=file:///~/Documents/263-E99658601-uat/CoursePacages/PackageCourse/252.mp4,
WebKitErrorMIMETypeKey=video/mp4,
NSLocalizedDescription=Plug-in handled load
}
解決方案
可忽略此錯誤,同理還有其他同類錯誤:
-
當(dāng)網(wǎng)頁內(nèi)部鏈接跳轉(zhuǎn)時
[error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == NSURLErrorCancelled
-
當(dāng)網(wǎng)頁包含
appstore
鏈接時[error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102
-
當(dāng)鏈接就視頻路徑時(不影響視頻正常播放)
[error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 204
具體代碼
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if ([error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == NSURLErrorCancelled) {
NSLog(@"Canceled request: %@", webView.request.URL);
return;
}
else if ([error.domain isEqualToString:@"WebKitErrorDomain"] && (error.code == 102 || error.code == 204)) {
NSLog(@"ignore: %@", error);
return;
}
[ViewUtils simpleAlertView:self Title:@"error" Message:[error localizedDescription] ButtonTitle:@"sure"];
}
其他錯誤
解決上述問題時假夺,發(fā)現(xiàn)這個問題 Domain=WebKitErrorDomain Code=101 "The operation couldn’t be completed. "
原因是鏈接字符串中含未轉(zhuǎn)義的字符,比如空格斋攀、豎線已卷、百分號、中文字等淳蔼。
解決方案
// [error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 101
urlString =[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];