Insert textual instructions with the google map API - ios

I use the google maps API to trace the route between two points, my code is this :
NSString *urlString = [NSString stringWithFormat:#"https://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&hl=fr&output=embed&om=5",latUtilisateur,longUtilisateur,latStation,longStation];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlString];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
However, this didn't has the textual instructions feature. Am i missing some parameters in the request above or something else?

The output=embed parameter is resulting in the full screen map. You can try a couple of alternatives:
For the standard map/directions page.
http://maps.google.com/maps?saddr=Sydney&daddr=Brisbane&hl=fr&output=html&om=5
For a mobile friendly directions
page. This version includes links to
static maps for each step of the
journey.
http://maps.google.com/maps?saddr=Sydney&daddr=Brisbane&hl=fr&output=mobile&om=5

Related

How to use different User-Agent in different iOS Webview request

I know I can use the below code to change the default agent:
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:#"Your user agent", #"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
but I want to request a different User-Agent for different requests. Examples: request 'www.google.com', use agent=‘google Agent’, request 'www.github.com', use agent='github Agent'.
I have tried the below way to set the 'User_Agent' in each request, but it doesn't seem to work.
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.amazon.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[requestObj setValue:#"Foobar/1.0" forHTTPHeaderField:#"User_Agent"];
// But the value is not "Foobar/1.0"
NSString* secretAgent = [webView stringByEvaluatingJavaScriptFromString:#"navigator.userAgent"];
NSLog(#"agent - %#", secretAgent);
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
One more question:
It seems a change to the default agent only work change in 'AppDelegate' or 'initialize'. Am I right? Because I try to change in 'viewDidLoad' but it doesn't seem to work.
I observed that if you load any url in webView with a user-agent set
to it. After some time you load the different url & different user
agent but used the same allocated WebView instane.The web view will
load the new url but can not set new user-agent. It just set old one
that you have set before loading first time.
You can not change untill you initiate new instanse of UIWebview(or
we can say that user agent can be set once per session). So I coame to result that user-agent can be set only once.
What I did for this problem is, I allocated new instance when I want set new user-agent.
You don't need to set it using JavaScript.
You have misspelled User-Agent. Use this minimal code taken from here
NSString* userAgent = #"My Cool User Agent";
NSURL* url = [NSURL URLWithString:#"http://whatsmyuseragent.com/"];
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setValue:userAgent forHTTPHeaderField:#"User-Agent"];

UIWebView does not load full content from an url

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

UIWebView not displaying URL

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.

Docx support in UIWebview(iOS)?

I have checked the official links for doc support, and it's clear that docx is not supported in UIWebview.
But, I also found out that some guys were able to open docx files in UIWebview:
Cannot open docx file through webbrowser in app using OpenIn functionality
Why doc and docx losing style information in iOS?
How to open Microsoft Office documents in iPhone
Also, afaik, iOS safari browser is built upon UIWebview and I am able to open docx files from internet in the browser.
However, when I download a docx from my test server (I have cross checked the downloaded docx by importing it from simulator and it opens perfectly on my mac), I am unable to view it in UIWebview.
I am confused,
Is docx Supported or not?
Or it seems that docx has further variety of formats out which some are supported?
Here is my loading code:
NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
[webViewForDocsView loadRequest:request];
Yes UIWebView supports the docx. Just tried loading a docx file from bundle and it seems working fine(in this example named "DOC1.docx")::
NSString *path = [[NSBundle mainBundle] pathForResource:#"DOC1" ofType:#"docx"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[mywebView loadRequest:request];
and If you are trying to display a docx file residing on a server somewhere, you can simply load it to your web view directly:
NSURL *targetURL = [NSURL URLWithString:#"http://www.central.wa.edu.au/Current_Students/JobsCareersandLeavingCentral/Documents/Resume%20Template.docx"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[mywebView loadRequest:request];
Don't know why but using the URL scheme to load docx didn't work, (below code didn't work)
NSURLRequest *request = [NSURLRequest requestWithURL:urlPath];
[webViewForDocsView loadRequest:request];
Instead, loading the file in memory(using NSData) and loading the data with MIME type worked (the below code worked like charm!)
NSString *path = [urlFileInView path];
NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
webViewForDocsView.delegate = self;
[webViewForDocsView loadData:data MIMEType:#"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:#"UTF-8" baseURL:nil];
Using UIWebView to display select document types
As per the Apple documentation, docx isn't supported by UIWebView and is deprecated.
To open docx in app use UIDocumentInteractionController.
DispatchQueue.main.async {
let docOpener = UIDocumentInteractionController.init(url: fileURL)
docOpener.delegate = self
docOpener.presentPreview(animated: true)
}

Facebook feeds on iOS app?

How can I display face book feeds related to a group on an iOS App?
Is there any JSON/JSONP call to fetch the feeds??
Any help is Appreciated.
The simplest - is just to show a web page on web view. Facebook manages itself to fit the width of your webView control.
// Load facebook data
NSString *fbUrlAddress = #"http://www.facebook.com/FLORtiles"; // here you put your own group
//Create a URL object.
NSURL *fbUrl = [NSURL URLWithString:fbUrlAddress];
NSString *webHTMLfb = [NSString stringWithContentsOfURL:fbUrl encoding:NSUTF8StringEncoding error:NULL];
//NSLog(#"webHTML of facebook: %#", webHTMLfb);
//URL Requst Object
NSURLRequest *fbRequestObj = [NSURLRequest requestWithURL:fbUrl];
//Load the request in the UIWebView.
[fbWebView loadRequest:fbRequestObj];
You might need to get familiar with Facebook's Graph Api
Go through this -> https://developers.facebook.com/docs/mobile/ios/build/

Resources