create a UIWebView and load a website programmatically - iphone

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/

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

How to implement google search application in iphone

I am new to iPhone development. I am making an application where I need to implement Google Search application and display the results below...
Can anyone please help if there is any tutorial to implement this application. Is there any tutorial?
I think the code given below is right, if so then what else should be added to make it work?
Thank you
NSLog(#"%#",searchBarGoogle.text);
NSString *string1 = [[NSString alloc] initWithFormat:#"%#",searchBarGoogle.text];
NSString *string = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",string1];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
in your .h file
#import <UIKit/UIKit.h>
#interface eddwedViewController : UIViewController {
IBOutlet UITextField *searchtextField;
}
-(IBAction)search;
#end
In your .m file
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
-(IBAction)search
{
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",searchString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAddress]];
}
In your view controller.xib make a textfield connect delegate with file owners and outlet with its name.
Make a button and connect it action with search method.
Let me know if it is working for you.
try this:-
NSString *searchString=#"apple";
NSString *urlAddress = [NSString stringWithFormat:#"http://www.google.com/search?q=%#",searchString];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
It is working fine.Hope It will help you.
what you can do is:-
NSString *searchString = searchBarGoogle.text;

uiwebview not loading the web page

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

Going to a UIWebView from an IBAction

I would like to know how do I load a web view from an "- (IBAction) buttonPressed" function.
IBOutlet UIWebView *webView;
-(IBAction)click
{
NSString *urlAddress = #"http://www.google.com";
//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];
}
Make the -(IBAction) load a new view, and put a UIWebView in that new view.

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..