Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序不运行时发出警报';我没有互联网连接_Ios_Objective C_Xcode_Uiwebview - Fatal编程技术网

Ios 应用程序不运行时发出警报';我没有互联网连接

Ios 应用程序不运行时发出警报';我没有互联网连接,ios,objective-c,xcode,uiwebview,Ios,Objective C,Xcode,Uiwebview,我在UiWebView中有一个需要internet连接的应用程序,我想在应用程序没有internet连接时显示一点警报。我试过了 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Message!" pr

我在UiWebView中有一个需要internet连接的应用程序,我想在应用程序没有internet连接时显示一点警报。我试过了

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {


    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Alert" message:@"Message!" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ok =  [UIAlertAction
                          actionWithTitle:@"OK"
                          style:UIAlertActionStyleDefault
                          handler:^(UIAlertAction * action)
                          {
                              [alert dismissViewControllerAnimated:YES completion:nil];

                          }];


    [alert addAction:ok];

    [self presentViewController:alert animated:YES completion:nil];
}

但这对我不起作用。当我在没有互联网连接的情况下启动应用程序时,它每次都会崩溃。有什么想法吗?谢谢你的帮助

导入Reachability.h并使用此代码

 if ([[Reachability reachabilityForInternetConnection]currentReachabilityStatus]==NotReachable)
        {
             //connection unavailable
        }
        else
        {
             //connection available
        }
这里是你们可以下载的链接


您的系统是否收到任何错误消息?在日志中?堆栈转储?无:(当我没有启用internet连接时应用程序崩溃,但如果我有连接,它会正常工作。当我有internet连接时,它会正常工作,但如果我设置了连接,则由于未捕获的异常“NSInvalidArgumentException”,原因:“***-[NSURL initWithString:relativeToURL:]:nil字符串参数'Put if(relativeToURL){}else{}