How can I use UIWebView in Objective-C to display a Webpage - iphone

I've been trying to implement UIWebView into my application for a while now but when I do my application crashes upon startup.
My code is:
-(void)viewDidLoad {
[super viewDidLoad];
NSString *urlAdress=#"http://www.facebook.com";
NSURL *url = [NSURL URLWithString:urlAdress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
The Debugger says Thread 1: Stopped at breakpoint 4

Your problem is that you have breakpoints set. See the blue arrow in the narrow column immediately left of your code? You have three of them set. You can disable the break point by clicking on the blue breakpoint arrow so that it dims (disabled). You can remove the breakpoint by right clicking on the blue arrow and removing it. A second way to remove it is to click and drag the breakpoint into the main window of your code, causing it to use the same dissolve animation used on the Mac OS X dock when you remove an item from it.

Related

Issue in playing vimeo video in webview

In my app there is a vimeo video. I have opened it in WebView using following code ;
NSURL *url = [NSURL URLWithString:#"https://vimeo.com/47278503"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:req];
And place one cancel button above the WebView to close the vimeo video.
But the problem is that audio still plays after closing the WebView by clicking that cancel button.
And another issue is that on viewing full screen, video is not showing ,only audio plays in background and after clicking cancel button the video is playing in background.
UPDATE :
There is a similar issue in link. I have tried it's code but it doesnt work. I have written the code
[self.view addSubview:self.view.window.rootViewController.view];
in tableview's didSelectRowAtIndexPath() method. (and this tableview is in popover).
I have also tried [self.view addSubview:self.view.window.rootViewController.view]; in WebView's viewDidLoad() , but it doesnt work.
What can be the issue ?
Thanks.
for stop BG sound. you just remove, release and set nil to your UIWebView.

How to Load a WebView pre-zoomed in? (In Xcode / Objective C)

I am loading a UIWebview of a hosted .jpg. It's actually a schedule, so it is a rather large image. Instead of having users have to zoom in right away, I would like to load the web view already zoomed in. Although I still need the user to be able to zoom in and out, and scroll. Basically I am just looking for an "initial" zoom. How would I accomplish this? Just FYI I put the method below I am using to load the image...Thanks!
// Webview code
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];
In iOS 5 you can access the UIWebView's scrollView property and set the zoom level on it after the page has loaded. That would likely work as you wanted. To get the same thing on pre-iOS 5 you'd probably want to go through the UIWebView's subviews until you find a UIScrollView and do the same thing on that.
I don't think there's any other way to programatically zoom it. Unless you can do it with Javascript and execute some using UIWebView's stringByEvaluatingJavaScriptFromString: method.

How to program UItoolbar buttons to load a new website in UIWebView?

I am working on an IPhone app and i have a UIWebview that by default loads a url.
I need to create a UIToolbar with three buttons under UIWebview which will allow users to hit the buttons and load a new url in UIWebview?
you have to add three buttons to your toolbar( This can be easily done by using the Interface builder(IB) and connect them to there respective IBAction in the IB.
now when tap on a a button you can do like this.
you have a UIWebView say myWebView //declared in .h file and properly linked with the your View using IB.
when you are done with the basic initialization
for button1 press
-(IBAction)button1:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
so by clicking on the button1 google webpage is loaded in your webView.
do the same for other button also.
:)
These methods and properties of UIWebview maybe help:
- (void)reload;
- (void)stopLoading;
- (void)goBack;
- (void)goForward;
#property(nonatomic,readonly,getter=canGoBack) BOOL canGoBack;
#property(nonatomic,readonly,getter=canGoForward) BOOL canGoForward;
#property(nonatomic,readonly,getter=isLoading) BOOL loading;

What happens in UIWebView when "Go" Button is touched

If you have a UIWebView with a textfield and a button that takes the value from that textfield and then performs some action.
When you touch the textfield, the keyboard is displayed with a Go Button. I'm trying to figure out what exactly happens under the hood when that Go Button is pressed?
How I would simulate that action programmatically?
The following will be used, when user press on GO button of Keyboard ...
NSString *urlAddress = mytextFieldText.text;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL];
//load the index.html file into the web view.
[aWebView loadRequest:aRequest];
Thanks
Check the below SO post for listening to keyboard GO button in UITextField.
Dismiss iphone keyboard

iOS button to webpage with uiwebview

For a current project I am embedding a mobile site into an iOS app. I've taken use of the goback() and goforward() functions, with UIWebView. But how would I make a custom function that onClick (or onTouch which ever is the correct term) Sends the UIWebView back to the page initially loaded? Any Help would be much appreciated as I have bene unable to find anything on the web thus far.
Add something like to the implementation file:
- (IBAction)loadPage:(id)sender;
{
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
And add this to the header file (each line at the appropriate position):
- (IBAction)loadPage:(id)sender;
IBOutlet UIWebView *webView;
Then bind the button to loadPage within interface builder,
and bind webView to the UIWebView.
Response to comment:
I created this sample project, hopefully it helps:
- http://dd5.org/static/iPhone_Browser_Sample.zip
Binding the button:
Right-click and drag to the class where you added the code above.
Release the button. Now a little dark-gray panel should appear.
Then click on the loadPage: entry within that panel.
If the code was added correctly, the entry should show up there.