I am trying to build an RSS reader for the Tom's Hardware website.
I have an error when I try to load an URL into an UIWebview from an RSS link.
Here'is my code:
- (void)viewDidLoad {
[super viewDidLoad];
if (self.url != nil) {
NSURL *requestUrl = [NSURL URLWithString:self.url];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:requestUrl];
[webView loadRequest:requestObj];
}
}
The url is setted by the parent controller.
When the URL comes directly from the RSS, I have an error in log:
[2234:207] Error Domain=WebKitErrorDomain Code=101 UserInfo=0x3a6a240 "Operation could not be completed. (WebKitErrorDomain error 101.)"
When I set manually the URL with the same URL like below, it work !
self.url = #"http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12";
Here is an URL exemple: http://www.presence-pc.com/tests/fraude-financiere-paget-macafee-23198/#xtor=RSS-12. I have no idea about that problem.
I hope you can help me.
Best regards.
Thanks guy, that'it, I have split the URL like this:
NSArray *split = [url componentsSeparatedByString:#"#"];
NSURL *requestUrl = [NSURL URLWithString:[[split objectAtIndex:0] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
and now it work , thanks for your help !
I have this code which also triggers error code 101
_request = [NSURLRequest requestWithURL:[NSURL URLWithString:redirectUrl]];
[editorWebView loadRequest:_request];
RedirectURL is an NSString which has this format http%3A%2F%2Fwww.linkedin.com%2Fnhome%2F
I tried removing percent escapes using the method of NSString and it now works.
[redirectUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
I think the problem can be the anchor in your URL, a friend got the same problem
Related
in the new safari on the mac they have a bar that can distinguish between google and a url.Thats what i am trying to do. I am wondering what i am doing wrong. It only wants to google not search url. Thanks in advance.
-(IBAction)SearchAll:(id)sender
{
if (googlebar) {
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.co./search?q=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
else{
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
}
Firstly, your code is way off. You will not achieve your goal this way.
Secondly, You should start off your IBAction statement by checking if the string that was input into the search bar (or urlbar whatever you want to call it) has a prefix of .com or .org...etc. If it does not then it then google searches the text in the UITextfield.
are you sure of your if statement?
you're using searchbar in the else, where searchbar if supposed not to exist.
you should also check the google.co./search url. I'd use google.com/search as it will save you a redirect
I'm still confused by your question though, as you have two toolbars: searchbar and googlebar, not one as in the latest safari for mac
I want my app to recognize if the current contents of the Clipboard are a URL, and if it is, I want it to load that URL into a web-view.
I'm using the following statement to do this checking:
if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:#"public.url-name"]])
...code to load the URL into the webView
but its not working - the IF statement always returns as FALSE, even when the clipboard's contents are clearly a URL.
Strangely enough though, when I remove this IF statement and just go ahead and load the URL I read from the Clipboard into the webView it works perfectly well. So its definitely just the IF statement that's not working for some reason.
Here's the full code:
// executed on a Button-click:
-(IBAction) showClipBoard {
pasteboard = nil; // resetting the pasteBoard each time
pasteboard = [UIPasteboard generalPasteboard];
NSURL *tempURL = pasteboard.URL;
//Check the pasteboard's value-type:
if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:#"public.url-name"]]) {
NSLog(#"URL is: %#", pasteboard.string);
NSURL *url = [NSURL URLWithString: pasteboard.string];
NSURLRequest *req = [NSURLRequest requestWithURL: url];
[webView loadRequest:req];
}
else
NSLog(#"=NOT a valid web-address");
NSString *tempString = [pasteboard valueForPasteboardType:#"public.utf8-plain-text"];
// Show the URL in a text-view box called "clipText":
clipText.text = tempString;
}
Anyone see what's wrong here?
You've probably figured this out by now, but, I ran into the same issue & the following worked for me :-
if ([pasteboard containsPasteboardTypes: [NSArray arrayWithObject:#"public.url"]])
...code to load the URL into the webView
I am currently trying to find a solution to this task. Essentially I have an initial UIView that asks for the users username and password for a specific site, this information would then get past onto the next view which has a UIWebView inside. I would like to know if its possible to automatically fill in the username and password details on the site and send the user directly to their account page on the site.
Thanks.
assuming your website has div tags you can inject using stringByEvaluatingJavsScriptFromString.
This example injects a username into the twitter sign up page. You can test it by loading this in your viewDidLoad:
NSString *urlString = #"https://mobile.twitter.com/signup";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
and then in webViewDidFinishLoad inject the username:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
[webView stringByEvaluatingJavaScriptFromString:#"var field = document.getElementById('oauth_signup_client_fullname');"
"field.value='yourUserName';"];
}
sorry, just realised you already had the solution but were missing the implementation. Hope the above helps.
btw to add a dynamic variable into the injected javascript use:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
NSString *injectedVariable = #"userNameHere";
NSString *injectedString = [NSString stringWithFormat:#"var field = document.getElementById('oauth_signup_client_fullname'); field.value='%#';", injectedVariable];
[webView stringByEvaluatingJavaScriptFromString:injectedString];
}
on solution is to "fake" the login request using the username and password and feed this into the web view.
I.e. you have a page index.php which has a username and password field.
if you fill them in, the page login.php is called with those parameters.
you could build an
NSString *urlString = #”http://www.yoursite.com/login.php?username=user&password=pass”;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
that should do the trick
I´m trying to open street view in UIWebView but it doesn´t work. I can see just normal maps. How can I solve it? Any other possibilities?
that´s my code:
NSString *urlAddress = #"http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webV loadRequest:requestObj];
Try loading this code for your UIWebview:
NSString *latLongString =[NSString stringWithFormat:#"%f,%f", latitude, longitude];
[_uiWebView loadHTMLString:[NSString stringWithFormat:#"<html><head><meta name='viewport',user-scalable=no'/><script src='http://maps.google.com/maps/api/js?sensor=false'type='text/javascript'></script></head><body onload=\"new google.maps.StreetViewPanorama(document.getElementById('p'),{position:new google.maps.LatLng(%#)});\" style='padding:0px;margin:0px;'><div id='p' style='height:100%%; width:100%%;'></div></body></html>",latLongString] baseURL:nil];
No. U can't achieve this .
see here
but u can like this
http://maps.google.com/?q=Tokyo#35.680,139.769
u can pass this link to ur webview to load it.
see here
Does MapKit allow for StreetView?
Simply Run the Google map url request in your webView and in webViewDidFinishLoad method add this below line to hide alert.
webView.stringByEvaluatingJavaScriptFromString("document.getElementsByClassName('ml-unsupported-link-dialog-container')[0].style.display='none'")
Here is a sample call to load Google StreetView in UIWebView. I used Swift.
let urlAddress = "http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=bran+castle&sll=44.439972,26.096894&sspn=0.000869,0.003664&ie=UTF8&hq=Bran+Castle&hnear=Bran+Castle,+Strada+General+Traian+Mo%C8%99oiu+nr.+28+E574,+Bran+507025,+Romania&t=k&layer=c&cbll=45.516381,25.368123&panoid=0d7jjq7vdWGTxFyonEKnBQ&cbp=12,209.81,,1,-18.52&ll=45.516381,25.368123&spn=0,0.008444&z=17";
let request = NSURLRequest(URL: NSURL(string: urlAddress)!)
glWebView.loadRequest(request)
I want to open an iTunes link in my webView, but when the webView launches the page, it redirects to the Safari browser. There, the url is getting opened, but I want it to open in my webView.
- (void)viewDidLoad {
NSString *urlAddress = #"http://itunes.apple.com/us/app/foodcheck-traffic-light-nutrition/id386368933?mt=8";
//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];
[super viewDidLoad];
}
Please suggest a way to sort out this problem.
You may want to try logging the load requests when you run the app. It may be that apple is automatically changing http:// to itms-apps or http://phobos or something along these lines. If so, then you can block the load when it's call using something like this:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *loadURL = [[request URL] retain];
NSLog(#"%#",loadURL);
if([[loadURL absoluteString] hasPrefix:#"http://"])
{
[loadURL release];
return TRUE;
}
[loadURL release];
return FALSE;
}
Good luck. I'm curious to know what finally works.
A note from the Apple reference documents- Q: How do I launch the App Store from my iPhone application? Also, how do I link to my application on the store?
Note: If you have iTunes links inside
a UIWebView, you can use this
technique after intercepting the links
with the -[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:]
delegate method.
Not sure if you ever got it working, but this works well for me:
NSString *responseString = [NSString stringWithContentsOfURL:myURL];
[self.webView loadHTMLString:responseString baseURL: nil)];