【问题标题】:Reachability from link on webview可从 webview 上的链接访问
【发布时间】:2013-03-26 00:51:34
【问题描述】:

我在资源包中有一个 html 文件,它显示在 web 视图中。 html页面上有访问网络网站的链接。每次在 html 页面上触摸链接时,我都想检查可访问性。我该怎么做?

Reachability 的 iOS 示例代码直接对 html 页面进行了测试。如何检测何时在 html 页面上触摸链接。我猜这与设置通知有关,但我不知道该怎么做。

【问题讨论】:

    标签: html ios webview reachability


    【解决方案1】:

    <UIWebViewDelegate> 方法 webView:shouldStartLoadWithRequest:navigationType: 将帮助您。在您的委托中实现它,并在那里执行您的可达性测试,并根据需要返回 YES 或 NO。

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        NSLog(@"loading %@", request);
        return YES;
    }
    

    【讨论】:

    • 我已经这样做了,并且捆绑包中的初始页面会产生与 Web 页面相同的“无连接”错误。我希望第一页不检查互联网状态并从捆绑中显示。然后我想打开可达性测试。我还没有弄清楚如何绕过 bundle 中第一页的 shouldStartLoadWithRequest。
    【解决方案2】:

    在 HTML 中使用这个 javascript 函数来了解可达性

    function CheckOnlineStatus()
        {
            var returnValue = false;
            
            // do your thing!function checkConnection() {
            var networkState = navigator.network.connection.type;
            
            var states = {};
            states[Connection.UNKNOWN]  = 'offLine';
            states[Connection.ETHERNET] = 'Ethernet connection';
            states[Connection.WIFI]     = 'WiFi connection';
            states[Connection.CELL_2G]  = 'Cell 2G connection';//Cell 2G connection
            states[Connection.CELL_3G]  = 'Cell 3G connection';//Cell 3G connection
            states[Connection.CELL_4G]  = 'Cell 4G connection';//Cell 4G connection
            states[Connection.NONE]     = 'offLine';
            
            
            if(states[networkState] != 'offLine')
            {
                returnValue = true;
            }
            
            return returnValue;
        }
    

    【讨论】:

    猜你喜欢
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2015-10-19
    • 2012-08-16
    相关资源
    最近更新 更多