Below is the code i have tried:
HTMLBrowserViewController.h
IBOutlet UIWebView * webControl;
HTMLBrowserViewController.m
webControl.scalesPageToFit = YES;
webControl.contentMode = UIViewContentModeScaleAspectFit;
webControl.delegate = self;
NSURL *url1=[NSURL URLWithString:webUrl];
NSURLRequest *requestObject=[NSURLRequest requestWithURL:url1 cachePolicy:NSURLCacheStorageAllowed timeoutInterval:15];
[webControl loadRequest:requestObject];
If you are trying to load an HTTP URL only, please check and enable the AllowArbitaryLoad In the App Transport Security Settings in the info.plist. You can refer to the following link.
Transport security has blocked a cleartext HTTP
If you are using the https URL, please make sure the URL is loading fine in the Safari and as well as in the Chrome browser responsive mode.
Sometimes, the website will load the response URL in iFrame. so please check that pass the correct URL.
Also, print the URL before you pass to the UIWebView, sometimes it should have space and as well as & so remove the same and pass it in the WebView.
serviceBookingUrl = [
NSURLRequest requestWithURL : [
NSURL URLWithString : [
websiteURL stringByReplacingOccurrencesOfString : # "&" withString : # "&"
]
]
];
[PrimaryWebView loadRequest: serviceBookingUrl];
Add NSAppTransportSecurity in your application .plist file
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Check this link transport Security has Blocked a cleartext HTTP
try this :
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"urlString %#",encodedString);
NSURL *url = [NSURL URLWithString:encodedString];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// Set delegete
webView.delegate=self;
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
Related
I have to write very simple application whoes open link in UiWebView but I have a little problem because I want that UiWebView download link from outside data e.g. http://www.example.com/link.txt and check link on every run of application. I tried to download data to NSStringbut I don't have any ideas how to use this with UiWebView. Thanks for help!
Create an NSURLRequest with the URL you downloaded. Then you can change the WebView's content with loadRequest(_ request: NSURLRequest)
Swift 2.2:
let myURLString = "the url you read from the file"
let url = NSURL(string: myURLString)
let request = NSURLRequest(url)
//assuming, the property webView is the UIWebView you want to change
webView.loadRequest(request)
Objective-C:
NSString * myURLString = #"the url you read from the file";
NSURL * url = [[NSURL alloc] initWithString:myURLString];
NSURLRequest * request = [[NSURLRequest alloc] initWithURL:url];
//assuming, the property webView ist the UIWebView you want to change
[self.webView loadRequest:request];
More information:
UIWebView
NSURLRequest
NSURL
I am loading one URL in UIWebView. It calls webViewDidFinishLoad delegate method but load an error page.
To load URL, I have used below code:
[customwebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:customURL]]];
Then I tried same URL in the Safari browser and it gets perfectly loaded.
This is the case only with iPhone4 with iOS 7.1.2.
I tried in simulator and device. Result is same.
Is there anything I need to set manually to load URL in UIWebView which is bydefault ON in Safari?
i was also not able to load urls like Facebook share dialog and twitter share.
But i got it fixed by encoding the url
use this :
NSString *encoded = [self.link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:encoded]];
self.webView.delegate = self;
[self.webView loadRequest:request];
I have a UIWebView where i load a url. But it does not load full content. I have checked all possible forums for solution but couldn't find a breakthrough yet. Any help would be really appreciated? You can try out the below url yourself. Basically, the url is supposed to contain html5 content/player.
-(void)loadPlayerUrl
{
activityIndicatorView.hidden = NO;
NSURL* nsUrl = [NSURL URLWithString:#"http://watch.nimbletv.com/tv"]
NSURLRequest* request = [NSURLRequest requestWithURL:nsUrl cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[self.playerWebView loadRequest:request];
}
However, this works perfectly in safari or any other browser.
You should create ViewControllerWebPage
Then
- (void)viewDidLoad
{
[super viewDidLoad];
self.screenName = #"Info Ekran";
NSURL *mobileCreaURL = [NSURL URLWithString:#"http://mobilecrea.com/"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:mobileCreaURL];
[mobileCrea loadRequest:myRequest];
}
Also create new view, select your new custom class (ViewControllerWebPage) and than create UIWebView
Pretty easy enough problem, but It's driving me crazy. I connected my uiwebview to the .h and called it myWebView. then in the viewdidLoad, i did this:
NSString *urlString = #"www.google.com";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
But when I run the app I just see a blank screen...
I don't know what's going on.
All help is appreciated, thanks
Your urlstring isn't well-formed (for your intent)
Use http://www.google.com/
Technically www.google.com is a valid URL (according to things like RFC 1738 and 3986), but since it lacks the scheme (the http part), the UIWebView doesn't quite know what to do with it.
I am storing website addresses from users in regular NSStrings.
Some are given as "www.somewebsite.com" and some as "http://somewebsiteothersite.org".
My app should open a UIWebView and open that webpage:
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:[self websiteString]]];
NSLog(#"visiting: %#",websiteString);
[webView loadRequest:requestObj];
But what happens is that if the http:// is omitted, the UIWebView won't open the page.
Is there a descent way to build the NSURL correctly for UIWebView?
Thanks!
Just add http:// if it's not there?
if (![urlStr hasPrefix:#"http://"] && ![urlStr hasPrefix:#"https://"]) {
urlStr = [#"http://" stringByAppendingString:urlStr];
}
beware of links that are intended to not have http:// for example ftp:// or mailto:
I know Mathiass answered quicker but I want to share a similar solution
//first detect if your string has contains http:// if not add http:// to your string
NSMutableString *websiteString = #"www.x.com";
if ([websiteString rangeOfString:#"http://"].location == NSNotFound) {
NSLog(#"contains http:// == false");
websiteString = [#"http://" stringByAppendingString:websiteString];
} else {
NSLog(#"contains http:// == true");
}
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:[self websiteString]]];
NSLog(#"visiting: %#",websiteString);
[webView loadRequest:requestObj];