Open link starting with http but not www

旧时模样 提交于 2019-12-20 04:34:10

问题


I want to open link starting with www they do not open. My code working only for http. Please help > I am newer in iOS.I shall be highly obliged.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{

    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        NSLog("User tapped a link.");
    }

    if ([request.URL.absoluteString rangeOfString:@"iosscrollposition:"].location != NSNotFound) {
        NSString *positionString=[[[request URL]absoluteString] stringByReplacingOccurrencesOfString:@"iosscrollposition:" withString:@""];
        NSArray *positionArray=[NSArray arrayWithArray:[positionString componentsSeparatedByString:@","]];
        NSInteger x=[[positionArray objectAtIndex:0] integerValue];
        NSInteger y=[[positionArray objectAtIndex:1] integerValue];
        if (initialYPosition != y || y==0) {
            if (initialYPosition!=0 ||x==0) {
                [myScrollView setContentOffset:CGPointMake(myScrollView.contentOffset.x,myScrollView.contentOffset.y+20) animated:NO];
            }
            initialYPosition=y;
        }
        if (x>320) {
            [webViewScrollView setContentOffset:CGPointMake(x-300,webViewScrollView.contentOffset.y) animated:NO];
        } else if(x<320) {
            [webViewScrollView setContentOffset:CGPointMake(0,webViewScrollView.contentOffset.y) animated:NO];
        }
        return NO;
    } else if([request.URL.absoluteString rangeOfString:@"http://"].location == NSNotFound) {
        return YES;
    } else {
        return NO;
    }
}

回答1:


NSURL *url=[NSURL URLWithString:@"http://"];

[self.myWebView loadHTMLString:tempString baseURL:url];



回答2:


Kindly add one more else if

else if([request.URL.absoluteString rangeOfString:@"www://"].location != NSNotFound) {
    return YES;
}

its also advisable to add, http:// before each URL you've, and for a note some URL may be of secure network so their extension can be https://.




回答3:


[self.myWebView loadHTMLString:tempString baseURL:[NSURL URLWithString:@"http://"]];



来源:https://stackoverflow.com/questions/26728275/open-link-starting-with-http-but-not-www

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!