I got my uiwebview working and displaying the specified url. the only problem is that the webpage that comes up is not the mobile webpage but the normal webpage. The same url in mobile safari opens the mobile version of the webpage but in my app it opens the normal version. Anyone know a reason for this? I am using storyboard if thats any help
Here is a snippet of my code:
NSURL *url = [NSURL URLWithString:website];
[webview loadRequest: [NSURLRequest requestWithURL:url]];
UIWebView does not send the same browser header as Safari, thus the web-server does not know which page to serve you app.
You could add an custom header to try and fix the problem.
NSURL *url = [NSURL URLWithString:website];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:#"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3" forHTTPHeaderField:#"User-Agent"];
[webview loadRequest: request];
You could see if there is a URL parameter you could add in for this specific site since they don't seem to check for the UIWebView agent when deciding to show mobile.
E.G. Maybe going to www.theirsite.com?mobile=true would accomplish it.
Related
I have built an application for iPhone.
In this app I need to use an url in the UIWebView.
I have implemented like this
NSString *urlAddress = #"http://chat.stackoverflow.com/faq";
// Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
// URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// Load the request in the UIWebView.
[documentsWebView loadRequest:requestObj];
The problem is that the web site is shown using zoom factor 100%. Hence my users have to scroll both vertically and horizontally. How do I adjust the zoom factor so that only vertical scrolling is required per default?
It sounds to me like you want to turn on:
documentsWebView.scalesPageToFit = YES;
On UIWebView there are many settings: enable/diable zoom, javascript, there are to many, better check documentation for that.
Your problem solution will be a server side html coding. There you need to check the client, his resolution and such.
Pls check in google "responsive layout" for html page.
No we cannot. It's web-server side check.
From the web-server side it required to check which client browser is being used (using user-agent).
Accordingly server will navigated to specific page or load css.
There is nothing required from device-end.
I am using search place API in my application ,its working fine.
But in Place API , am passing parameters map center coordinates and radius with API KEY.
its giving response. But,if i want to search any location whether its region visible in screen or not as in in-built map application . How should i go for this?is there any different query or API for achieving it ?
Right now , am using below query.
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=50000&types=&name=%#&sensor=false&key=aaaaaaaaaa",mapView.centerCoordinate.latitude,mapView.centerCoordinate.longitude,searchPlace.text]];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLConnection *connect;
connect = [[NSURLConnection alloc]initWithRequest:request delegate:self];
thank you very much.
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%#&output=csv",[searchPlace.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
you can try this... may be it's help you...
I have an IOS project with html file resources shown in a webview. These html files have different sections which correspond to fragments (eg, index.html#section1, index.html#section2), which I would like to load in the webview. Unfortunately using [NSURL fileURLWithPath:url] does not work with fragments. The # is converted to %23 in the url, and the file is not found. If I use the [NSURL URLWithString:url] method, it works, but this method cannot load local resources.
Is there a way to have the webview load the local resource url with the fragment?
As you have noticed, this seems to be impossible for file URLs, but you could use a workaround if you don't mind:
[webView stringByEvaluatingJavaScriptFromString:#"window.location.hash = '#section2';"];
It's not obvious how Apple intended this sort of navigation to be triggered. There might be several ways to do it, but this one does the trick for me:
NSURL *url = [NSURL fileURLWithPath:#"/full/path/to/index.html"];
NSString *fragment = #"#section1";
url = [NSURL URLWithString:fragment relativeToURL:url];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
I have written a script that download some HTML files into the Documents folder of my app! I want to load this files in my WebView, is that possible?
For example:
If index.html is present in Documents folder, load it, else load index.html in mainBundle!
Thanks to everyone can help me!
Sure, just use:
[webview loadRequest: [NSURLRequest requestWithURL: [NSURL fileURLWithPath: [#"~/Documents/index.html" stringByExpandingTildeInPath]]]]
The following line works in the device and simulator just fine:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.myURLgoesHere.com"]]];
The following lines (in various versions) works fine in the simulator, but won't load the page in the device. Any Suggestions?
NSURL *tempURL = [NSURL URLWithString:[SharedClass sharedSharedClass].myURL]; // myURL is a NSString in my shared class
[webView loadRequest:[NSURLRequest requestWithURL:tempURL]];
Why would this quit working when I go from a hardcoded string to my shared string? The shared string works fine in other views and even gets stored to a plist file just fine.
Wouldn't you know as soon as I post this it started working... must have been something funny with the URL like a space or ????