I have the following code in viewDidLoad
NSURL *url = [NSURL URLWithString:URL_TO_DOWNLOAD];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
When this is completed I want to view the URL (PDF) downloaded inside my UIWebView. I create a UIWebView programatically however I can't figure out a way to loadRequest my actual ASIHTTP Request.
you could display a pdf in your device by two way.
first by passing the url to UIWebView directly, in this case you do'nt require to download pdf file
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 360, 420)];
NSURL *targetURL = [NSURL URLWithString:#"http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/UIWebView_Class.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
And the second way , you first need to download (As you are doing) then get the path of pdf file from your application bundle,
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *pdfpath = [[NSBundle mainBundle] pathForResource:#"mypdf" ofType:#"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfpath ];
NSURLRequest *pdfRequest = [NSURLRequest requestWithURL:pdfURL ];
[webView loadRequest:pdfRequest];
[self.view addSubview:webView];
[webView release];
Related
I have UIWebView i want to load link in it but it does not show any thing here is the code which i am using it does not show
fileName has value http://www.google.com
NSURL *url = [NSURL fileURLWithPath:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
try like this,replace fileURLWithPath with URLWithString
NSString *fileName= #"http://www.google.com";
NSURL *url = [NSURL URLWithString:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview setScalesPageToFit:YES];
[webview loadRequest:request];
**fileURLWithPath** is used when there is a path containing your URL.
But in your case there is a direct URL so you should use like following
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"%#",#"http://www.google.com"]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
//Create a URL String.
NSString *urlString = [NSString stringWithFormat:#"http://www.google.com"];
//Create a Legeal URL object.
NSURL *MyUrl = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:MyUrl];
// set Fit page to WebView
[webView setScalesPageToFit:YES];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
NOTE : Don't forget to Add webView to self.View OR if you add with XIB then make sure you connection is proper;
Try this ..... !!!
UIWebView * aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
NSString *fileName= #"http://click-labs.com";
NSURL *url = [NSURL URLWithString:fileName];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[aWebView setScalesPageToFit:YES];
[aWebView loadRequest:request];
[ self.view addSubview:aWebView];
I am implementing instagram in my application.I am following the code from "https://github.com/crino/instagram-ios-sdk"
This code is working fine and instagram call is made in the app delegate.
"self.instagram = [[Instagram alloc] initWithClientId:APP_ID delegate:nil]"
But I want to use this in the view controller not in the app delegate.
When I try to do that it is not calling the "-(void)authorize:(NSArray *)scopes" method and so Instagram is not loading.
Please suggest me some way out for this.
Found the solution. My code:
self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
self.webView.delegate = self;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: [NSString stringWithFormat:kAuthenticationEndpoint, kClientId, kRedirectUrl]]];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
Where: kAuthenticationEndpoint=#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token%22;
My code:
UIWebView *webViewInstagram = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
webViewInstagram.delegate = self;
[webViewInstagram setDelegate:self];
[self.view addSubview:webViewInstagram];
NSString *urlRedirect = #"REDIRECT_URL";
NSString *clientId = #"CLIENT_ID";
NSString *url = [NSString stringWithFormat:#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=token",clientId, urlRedirect];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString: url] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30];
[webViewInstagram loadRequest:request];
I'm looking up web pages using UIWebView and NSURLRequest and it's working fine, but I want it to start with a blank page each time, rather than displaying the results of the last URL lookup. Is there an easy way to do that?
I'm doing this in viewDidLoad:
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
...and then I load the UIWebView like this:
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
Start with this first.
[wikiText loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#""]]];
This loads a blank page first. then open your usual URL.
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
We can also use Html tags like this
[wikiText loadHTMLString:#"<html><head></head><body></body></html>" baseURL:nil];
Then after you can load your actual url
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
There is no need to load load blank URL, you just use viewWillAppear, according to this, every time when your view will appear then webView will load your page and initially gives you white blank page then your url page.
-(void)viewWillAppear:(BOOL)animated
{
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
}
I would like to add to my app a pdf viewer which can scroll horizontally. Anyone know how to do it? I'm making several attempts but without success. Thanks. Matteo
Use UIWebViewController in landscape orientation and this piece of code can give you an idea about how to display pdfs:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake( 0, 0, 320, 480 )];
NSString *path = [[NSBundle mainBundle] pathForResource:#"about" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView release];
i want to store pdf file in local and read it . i want to read this pdf same as iphone read data in mkmapview.
means i want to create same as pdf(Acrobat) reader.how can i do this?
you can store the pdf in the application bundle and display it using a uiwebview:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSString *path = [[NSBundle mainBundle] pathForResource:#"document" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
to load it from an url you can do something like this:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSURL *targetURL = [NSURL URLWithString:#"http://www.mywebsite.com/myPdfFile.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
[webView release];
you can also download your pdf into the documentDirectory during runtime and load it from there.
i think you need this
http://github.com/akisute/iPhonePDF
from here you can find code (api) by that you can genrate pdf in iphone .
and also can do edit it.
Let me know this is what you need ?
You can open the PDF with iBooks or any other app that can read PDF files to store it locally on the Phone.