Web View Orientation iOs - ios

I am using a ModalViewController to open an web view in my app.
Inside my class, i've this piece of code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = #"address";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:requestObj];
}
Well, in my app the interface orientation is always in portrait mode. But, when i start the web view, a video will show up, and i need to change my interface to every kind of orientations.
Observation: I don't want to change on the class that i am running the modal view controller. I just want to change the orientation inside my video.

Related

UIWebview not showing editview on first tap

This is an issue with iOS9 and later.
On the load of application I select a word in UIWebview but theres no editview popup showing copy, share, define etc options on first tap.
From next selection after the tap it works fine.
even the -(BOOL)canPerformAction:(SEL)action withSender:(id)sender delegate returns NO for all options on first tap and select
Also when you select a word and scroll it up off the screen and try to select other word. the view scrolls up/down on its own and a worng word will be selected(View displaces itself by an offset of the amount the selected word is scrolled off the screen).
Pulling my hair to get this fixed. Any help would be appreciated
its simple code
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view becomeFirstResponder];
NSString *urlAddress = #"https://en.wikipedia.org/wiki/Main_Page";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_myWebView loadRequest:requestObj];
}
UIWebview has many bugs and is not memory efficient .
Replaced UIWebview with WKWebView on apple's recommendation and it fixed all the bugs.

How do I enable my back button only when a link is clicked in my UIWebView? (Code won't execute)

I'm trying to make it so that the back button will only be enabled when the user presses a link and/or if canGoBack = TRUE. I tried using an if statement in the body but that didn't work. I then tried using what I could find online and it still didn't work. My code is below. What am I doing wrong? Thanks!
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest: (NSURLRequest *)request navigationType: (UIWebViewNavigationType)navigationType{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
NSString *url = webView.request.URL.absoluteString;
NSURL *nsurl = [NSURL URLWithString:url];
NSURLRequest *nsrequest = [NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
backButton.enabled = TRUE;
}
return TRUE;
}
shouldStartLoadWithRequest() won't get called if you haven't set the web view's delegate.
In order to use UIWebView its typically set as an outlet property of a view controller, so you should have something like this:
IBOutlet UIWebView* webView;
The webView has a delegate property which needs setting to your view controller, you can set delegates in a storyboard, but its more explicit to set it in code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView.delegate = self;
99% of the time you just set delegates, but UIWebView's delegate is funny in that it needs setting to nil when finished with. So add this:
- (void)viewDidUnload
{
[self.webView stopLoading];
self.webView.delegate = nil;
UIWebView and WKWebView both have a canGoBack and canGoForward property on them. You can use KVO to see when these are enabled, and enable/disable your back and forward buttons accordingly.
http://nshipster.com/key-value-observing/

Add a custom UIWebView using Phonegap

I have an iOS app that needs OAuth authentication of a Facebook account, but I have to use my own server for the API calls.
So I want to open a FBLogin screen (UIWebView), with a login URL, when a certain button is clicked.
I have the following code:
FBWebViewController.h
#import <UIKit/UIKit.h>
#interface FBWebViewController : UIViewController <UIWebViewDelegate>
- (void)initFBWebView;
#end
FBWebViewController.m
- (void)initFBWebView {
NSLog(#"DetailViewController->initUIWebView {");
UIWebView *aWebView;
// init and create the UIWebView
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];
//Set the URL to go to for your UIWebView
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 URL into the web view.
[aWebView loadRequest:requestObj];
//add the web view to the content view
[self.view addSubview:aWebView];
}
and in my Authorize.m file, which handles all the API calls etc.
- (void)fbLogin:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
FBWebViewController *webview = [[FBWebViewController alloc] init];
[webview view];
[webview initFBWebView];
}
Nothing happens. No WebView is opened. I put some debug statements in the initWithFbWebView method, and the method is called and run until the end, but no screen is showing up.
What am I doing wrong?

Accessing the object of another class with

In my project iPad, I have a TableView that opens in a popoverController, tableView have this particular company in each cell, which was clicking to the site clicked COMPANY,
but found means to launch the User descomodo out of going to the safari app.
As I already had one in my WebView viewController which is a site with background, I decided to make the site selected in the table open in the background of the app.
How are separate classes I need a way to access the webViewHome or simply call the function that loads the site with another parameter.
I tried to access in tableView.m as follows:
viewController *varViewController = [[viewController alloc]init];
.....
- (void)mostraSite:(NSString *)endereco{
NSURL *url = [NSURL URLWithString:endereco];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[varViewController.webViewHome loadRequest:requestObj];
}
and each index of TableView call the function with a different parameter, but does not work.
if they have something to suggest I am grateful.
explaining more clearly
In my ViewController I have a webview.
eg
# import <UIKit/UIKit.h>
# interface iPhoneStreamingPlayerViewController: UIViewController
{
...
IBOutlet UIWebView * webViewHome;
...
}
# property (nonatomic, retain) UIWebView * IBOutlet webViewHome;
...
- (Void) mostraSite: (NSString *) address;
...
# end
the ... where I is Outlets and other functions. Not posted because it's just unnecessary.
I have a TabBar Controllers other that opens in a popover.
one of the items of the TabBar is a TableView that each cell contains a link, and when an item is selected, I want to open the site in the WebView I have in the ViewController.
in TableView,
imported the viewController
didSelectRowAtIndexPath and call the function passing the parameters as index
eg
viewController varViewController * = [[viewController alloc] init];
switch (indexPath.row) {
case 0:
[self mostraSite: # "http://www.radiobento.com.br"];
break;
calling the function
- (void) mostraSite: (NSString *) address {
NSURL * url = [NSURL URLWithString: address];
NSURLRequest requestObj * = [NSURLRequest requestWithURL: url];
[varViewController.webViewHome loadRequest: requestObj];
}

iPad SplitView detailView default load

I have an iPad split-view app. The detailview is a webview. In which method, can I get a default page loaded when the app launch before the user clicks on an item in the table view?
IN detailviewcotroller.h , create outlet as follows,
IBOutlet UIWebView *WEBVIEW;
connect outlet in xib by drag n droping uiwebview control.
In your detailviewcontroller.m's viewdidload method u can write as follows-
NSString *str=#"yr default webpage link here";
NSURL *url=[NSURL URLWithString:str];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
[WEBVIEW loadRequest:req];
Just a good advice, by creating Outlets, when you synthesize do:
#synthesize webView = _webView;
and use :
[_webView loadRequest:req];
for loading your request.

Resources