Skip to content

Instantly share code, notes, and snippets.

@niwatako
Created August 5, 2015 14:59
Show Gist options
  • Save niwatako/67146b5657954bbddbeb to your computer and use it in GitHub Desktop.
Save niwatako/67146b5657954bbddbeb to your computer and use it in GitHub Desktop.
WKWebViewのエラー処理は ユーザー操作によるキャンセルの error.code -999 を無視するべし。 #CodePiece
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error{
if (error && !([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled)) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Error : %ld",(long)error.code]
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil]];
// 続けるボタン
[alertController addAction:[UIAlertAction actionWithTitle:@"Retry"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// リロード処理の実装
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment