iOS 验证网址使用 webView

来源:互联网 发布:如何注册国家顶级域名 编辑:程序博客网 时间:2024/06/06 01:44

<UIWebViewDelegate>

/**

 *  链接跳转

 */

@property (nonatomic,strong)NSString *urlStr;

/**

 *  原理很简单 就是看网址链接有没有返回 此方法判断受网络影响

 */


- (void)setWeb:(NSString *)url {

    UIWebView *webView = [[UIWebViewalloc]initWithFrame:CGRectMake(0,0,0,0)];

    webView.delegate =self;

    if([url rangeOfString:@"http"].location !=NSNotFound){

        NSLog(@"包含http");

_urlStr=url;

    }else{

        NSLog(@"不包含http");

_urlStr = [NSStringstringWithFormat:@"http://%@",url];

    }

    NSURL *ur = [[NSURLalloc]initWithString:_urlStr];

    NSURLRequest *req = [NSURLRequestrequestWithURL:ur];

    [webView loadRequest:req];

    [self.viewaddSubview:webView];

    

}

/**

 *  调用代理方法查看是否有返回

 */

- (void)webViewDidFinishLoad:(UIWebView *)webView{

    if (webView.request) {

        NSLog(@"有返回");

    }

}


0 0