uiwebview not loading the web page - iphone

in my program uiwebview is not loading the url address.when i nslogged the request object is not null.however when i nslog the webview.request it returns null.what may be the reason it is not loading
- (void)viewDidLoad {
[super viewDidLoad];
self.web = [[UIWebView alloc] init];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSLog(#"%#",requestObj);
[self.web loadRequest:requestObj];
[web setFrame:CGRectMake(0, 0, 320, 370)];
NSLog(#"%# %#",self.web,self.web.request);
}
the nslog results are
<NSURLRequest http://www.google.com>
<UIWebView: 0xbb17ff0; frame = (0 0; 320 370); layer = <CALayer: 0xbb12f20>> (null)
as per suggestions from this site i changed it from IB and made it to code .i made the class confirm to uiwebview delegate..both the webviewdidstart and webview did finish are being called these are the nslog outputs from these methods
webviewdidstart
webView-----><NSMutableURLRequest >
webView-----><NSMutableURLRequest http://www.google.com>
webview did finish
webView-finished----><NSMutableURLRequest http://www.google.com>
webView-finished----><NSMutableURLRequest http://www.google.com>
still nothing is being called and i think both these methods are called twice

This is a working code, test this out in your application and let us know the outcome
in .h file, add UIWebViewDelegate
in .m file's viewDidLoad, add this:
UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,460.0)];
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:requestObj];
[self.view addSubview:webview];
Now check in the delegates if your page is loading or not:
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(#"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"finished loading");
}

try like this
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self addSubview:webView];
[webView release];

Related

Instagram login in iPhone sdk

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];

create a UIWebView and load a website programmatically

The following is my code. I simply want to load a website page and put a back button on screen. Don't know why nothing shows on the screen.
in .h
#import <UIKit/UIKit.h>
#interface ThirdViewController : UIViewController
{
UIWebView *myWebView;
}
#property (nonatomic, retain) UIWebView *myWebView;
-(IBAction)goBack:(id)sender;
#end
in .m
#import "ThirdViewController.h"
#implementation ThirdViewController
#synthesize myWebView;
-(IBAction)goBack:(id)sender
{
[myWebView goBack];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
[self.view addSubview:myWebView];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(goBack:)];
}
Initialize your webView.
UIWebView *tempWebview = [[UIWebView alloc]initWithFrame:theFrame];
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
self.myWebView = tempWebview;
[tempWebview loadRequest:requestObj];
[tempWebview release];
myWebView.delegate=self;
First Initialize Web view .Write The Below Code In Between [Super
ViewDidLoad]; and Nsstring Inisilization.
myWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
myWebView.delegate=self;
[self.view addSubview:myWebView]
Then Load Request Your Code Will Work.
Add the below code into your viewcontroller.m file viewDidLoad method.
UIWebView *webView = [[UIWebView alloc]init];
NSString *urlString = #"http://www.sourcefreeze.com";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
[self.view addSubview:webView];
for complete uiwebview example please refer the below link.
https://sourcefreeze.com/ios-webview-uiwebview-example/

how to call two url in one webview in iphone

i want to call two url in one webview one after the another but how i know i can load one url in webview but to call two url please help me one this how to timeinterval on both the url
this is mu single url if but i have to give here two url the how to give and call them
- (void)viewDidLoad {
[super viewDidLoad];
CheapFlightsAppDelegate* app=(CheapFlightsAppDelegate*)[[UIApplication sharedApplication]delegate];
self.navigationController.navigationBarHidden = true;
NSLog(#"Book: %#",app.selectedOutgoingFlight.FlightKey);
NSLog(#"Book: %#",app.selectedInComingFlight.FlightKey);
NSString *hel = #"http://www.bookryanair.com/SkySales/FRSelect.aspx?AvailabilityInputFRSelectView %24ButtonSubmit=Select%20and%20Continue&AvailabilityInputFRSelectView%24m arket1=";
NSString *hel1 =[NSString stringWithFormat:#"%#&",app.selectedOutgoingFlight.FlightKey];
NSString *hel2 = #"AvailabilityInputFRSelectView%24market2=";
NSString *hel3 = [NSString stringWithFormat:#"%#&",app.selectedInComingFlight.FlightKey];
NSString *hel4 = #"__EVENTARGUMENT=&__EVENTTARGET=";
NSString *urlAddress = [NSString stringWithFormat:#"%#%#%#%#%#",hel,hel1,hel2,hel3,hel4];
[spinner startAnimating];
spinner.hidden = NO;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
NSLog(#"Book: %#",urlAddress);
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
webView.delegate = self;
}
use this method
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:#"http://stackoverflow.com/questions/7670889/how-to-call-two-url-in-one-webview-in-iphone/7670992#7670992"]];
[webView loadRequest:request];
[self performSelector:#selector(loadAnother:) withObject:nil afterDelay:10];
-(IBAction)loadAnother:(id)sender{
NSURLRequest *requests=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:#"http://stackoverflow.com/questions/7683196/uitableview-with-text-that-is-both-right-aligned-and-indented"]];
[webView loadRequest:requests];
}
Set new url of NSURLRequest and call [webView loadRequest:requestObj]; after any time interval you want again.
NSTimer will help you to call method after some interval.
// after loading first url:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:#selector(loadNewUrl:) userInfo:nil repeats:NO];
//somewhere in delegate define selector
- (IBAction)loadNewUrl:(NSTimer *)timer
{
NSURL *url = [NSURL URLWithString:#"http://www.apple.com/stevejobs"];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
UPDATED:
Implement in your `` methods to detect when webview finished loading first url:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
In "webViewDidFinishLoad" delegate method get the current URL thats loaded using
currentURL = webView.request.URL.absoluteString;
Then check if it matches with your first URL and if it does, Load the second URL that you need to call. If you want, call this second URL after some time using a timer.

How to Add a PDF Document to a UIWebView using ASIHTTP

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];

website not upload using webview

ihave write the following code
but it does nothing in consloe it shows Unknown scheme, doing nothing
[webview setDeleagte self];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:sourcelinkStr]]];
NSString *strURL = #"https://facebook.com";
NSURL *url = [NSURL URLWithString:strURL];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:url]];
now ,
we have to define Methods For LoadRequest
thanks..