Using baseurl in UIWebView - ios

I have some issues loading a site that apparently has to do with needing to properly set a baseurl. The main site is http://www.oklahomachristianacademy.org and the site address I need to have open is a string that returns as
applewebdata://F6224B10-25ED...
So, in my code I thought this would work to set the baseurl and the string attached above to load into the app.
-(void)viewWillAppear:(BOOL)animated {
NSURL *theurl = [NSURL URLWithString:#"http://www.oklahomachristianacademy.org/"];
[savedweb loadHTMLString:(NSString *)link baseURL:(NSURL *)theurl];
}
However, this does not work, and the UIWebview simply displays the applewebdata:// line again. What am I missing?

use this code
//NSString *urlAddress = #"http://www.google.com";
NSString *urlAddress = #"http://cagt.bu.edu/page/IPhone-summer2010-wiki_problemsandsolutions";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];

Related

WebView Url not full load in iOS10?

Same url in run in lower then iOS10 (ex. iOS8,iOS9) work properly.
-(void) loadUrl
{
NSString *urlAddress = #"http://myurl.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[detailWebView loadRequest:requestObj];
}
I tried your code and it works fine in ios 10 and xCode 8.
I used this,
-(void) loadUrl
{
NSString *urlAddress = #"http://google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[self.webView loadRequest:requestObj];
}
And call this method where you want using [self loadUrl];
Add URLSchemes in your plist file for your url.
I am getting webview like,
Your code is not wrong.
Hope this will help you.
In apps that run in iOS 8 and later, use the WKWebView class instead of using UIWebView.import webkit.h and use this code
#import <WebKit/WebKit.h>
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
NSURL *nsurl=[NSURL URLWithString:#"http://www.apple.com"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];

Url not loading in UIWebview, # converting to %23

Stucked on load the below Local path url in UIWebview. Find the url in spinepath, then i converted to url [SpinePathUrl].
My issue is, when i try to load,i'm getting nil value.
For checking purpose, i pasted the SpinepathUrl into browser it show webpage not found.Then, i changed SpinePathUrl "arugoswami-4.xhtml%23toc_marker-4" into "arugoswami-4.xhtml#toc_marker-4", its showed result.
Is the # is my issue in url.? Why the # converted to %23, when it converting from String to Url.
spinepath = [NSString stringWithFormat:#"%#%#",documentsDirectory,Path];
spinepath = [spinepath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
spinepath = [spinepath stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[/Users/blazedream/Library/Application Support/iPhone Simulator/7.1/Applications/E19D2CD0-E0DC-460E-8BC9-97A9C8010910/Documents/UnzippedEpub/OEBPS/arugoswami-4.xhtml#toc_marker-4]
NSURL *SpinePathUrl = [NSURL fileURLWithPath:spinepath];
[file:///Users/blazedream/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/E19D2CD0-E0DC-460E-8BC9-97A9C8010910/Documents/UnzippedEpub/OEBPS/arugoswami-4.xhtml%23toc_marker-4]
NSURLRequest *request = [NSURLRequest requestWithURL:SpinePathUrl];
[webView loadRequest:request];
Try adding fragment manually
NSURL *baseUrl = [NSURL fileURLWithPath:#"... arugoswami-4.xhtml"];
NSURL *fullURL = [NSURL URLWithString:#"#toc_marker-4" relativeToURL:baseUrl];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:fullURL];
[myWebView loadRequest:urlRequest];

webview having trouble with redirects

NSURL *urlString = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];
//Load the request in the UIWebView.
[self.webview loadRequest:requestObj];
The UIWebView is having trouble with redirects. How can I make sure the uiwebview handles redirects properly?
In order to do a redirect from one site to another, just load your website, but add a BOOL var for checking if the right page is loaded.
BOOL page1Loaded;
then, if you need to change to another site, just create a global NSString var like so
// for site name
NSString *urlAddress;
and just update upon needing to
if(page1Loaded) {
// as seen in #Lithu T.V.'s comment, DO NOT FORGET the http:// or https://
// name of address
urlAddress = #"http://..." or #"https://..."
NSString *urlString = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];
//Load the request in the UIWebView.
[self.webview loadRequest:requestObj];
}
else {
// as seen in #Lithu T.V.'s comment, DO NOT FORGET the http:// or https://
// name of redirect
urlAddress = #"http://..." or #"https://..."
NSString *urlString = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlString];
//Load the request in the UIWebView.
[self.webview loadRequest:requestObj];
}
hope this helps!

UIwebView - load the URL it was left with upon dismissView

I have the following code that allows me to load a set URL each time, placed in my viewDidLoad method:
NSString *urlAddress = #"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
Now the user can of course go to any webpage from here and if the user decides to dismiss the view I want for them to be able to return to it.
Now I have this code, through reading various forums and searches:
again the viewDidLoad - now looks like this:
NSURLRequest *currentRequest = [_webView request];
NSURL *currentURL = [currentRequest URL];
if(currentURL != nil)
{
NSString *urlAddress = currentRequest;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}
else {
NSString *urlAddress = #"http://google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
}
and in my viewDidUnLoad I have this:
-(void)viewDidUnload {
NSURLRequest *currentRequest = [_webView request];
NSURL *currentURL = [currentRequest URL];
NSLog(#"Current URL is %#", currentURL.absoluteString);
[NSURLConnection connectionWithRequest:currentRequest delegate:self];
}
a) Am I on the right track for achieving this?
b) I have a warning created on this line : `NSString *urlAddress = currentRequest;
which is:
Incompatible pointer types initializing 'NSString *__strong' with an expression of type 'NSURLRequest *__strong'
Any help is appreciated:-)
Thank you:-)
PS I started this problem out in this question, but felt it was worth a new one, so forgive me if you do not think the same.
`
NSString *urlAddress = currentRequest;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
Could just be
[_webView loadRequest:currentRequest];
You might want to experiment with not unloading the view/view controller when the user dismisses it then there won't be a time delay when the user brings it back. (Maybe you could instead make it hidden instead of unloading it for example when the user dismisses it, or send it to the back of the navigation controller stack, assuming you have one as the root view controller).
P.S.
Your warning is because you're trying to assign an NSURLRequest object to an NSString object.

UIWebView Woes - Error 101

UIWebView won't load (Error 101) the following URL:
http://afrikaans.news24.com/Sci-tech/Nuus/Rwanda-gaan-Suid-Afrikaanse-wild-invoer-20111116
I have tried percentescapes to no avail. Please help!
Try this:
//Set the URL to go to for your UIWebView
NSString *webAddressString = #"http://afrikaans.news24.com/Sci-tech/Nuus/Rwanda-gaan-Suid-Afrikaanse-wild-invoer-20111116";
NSLog(#"show webAddressString: %#", webAddressString);
//Create a URL object.
NSURL *weburl = [NSURL URLWithString:webAddressString];
[webAddressString release];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:weburl];
//load the URL into the web view.
[aWebView loadRequest:requestObj];
Error 101 is The operation couldn’t be completed., which is led by either domain not found , network problem or even object allocation ( as searched from Google ) .
Try something like
NSString *unencodedURLString = #"http://afrikaans.news24.com/Sci-tech/Nuus/Rwanda-gaan-Suid-Afrikaanse-wild-invoer-20111116";
NSString *encodedURLString = [unencodedURLString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
//Create a URL object.
NSURL *weburl = [NSURL encodedURLString];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:weburl];
//load the URL into the web view.
[aWebView loadRequest:requestObj];

Resources