Google Sign-In button in WKWebView iOS not responding - ios

In my app the login page is in a WKWebView with an option to login using Google Auth:
https://developers.google.com/identity/sign-in/web/build-button
but the button doesn't respond.
Moreover, I've tried to switch the login URL with the URL above (google docs) because it containts an example for a Google login button and the button doesn't respond as well.
This is my WKWebView configuration with the google's doc link:
- (void)initWebView {
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero];
[self.contentView addSubview:webView];
[webView setTranslatesAutoresizingMaskIntoConstraints:NO];
[[webView.topAnchor constraintEqualToAnchor:self.contentView.topAnchor constant:0] setActive:YES];
[[webView.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:0] setActive:YES];
[[webView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor constant:0] setActive:YES];
[[webView.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor constant:0] setActive:YES];
self.webView = webView;
webView.navigationDelegate = self;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"https://developers.google.com/identity/sign-in/web/build-button"]];
[request setValue:[self getUserAgent] forHTTPHeaderField:#"User-Agent"];
[self.webView loadRequest:request];
}
When I'm trying to click the button with the safary's web inspector open I don't see any respond as well.
Any help will be appreciated, thanks.
P.S.: Just to be clear none WKWebView delegate is being called.

Apparently, since 2016, Google no longer allows OAuth requests to Google in embedded browsers known as “web-views”, as mentioned here.

Related

iOS: JavaScript can't run on WKWebView

I use WKWebView to show a web page. When I touch a button on the page, some javascript code should work and show me an alert view. But it doesn't work. If I open the page on Safari, it works well. Here is my code
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;
configuration.preferences.javaScriptEnabled = YES;
_webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:configuration];
self.view = _webView;
NSURLRequest *req = [NSURLRequest requestWithURL:[HPBNetworkBusiness getExamPageURL]];
[_webView loadRequest:req];
[_webView addObserver:self forKeyPath:#"URL" options:NSKeyValueObservingOptionNew context:nil];
WKWebView will not show JavaScript alerts automatically. It will be notified through
webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler: defined on WKUIDelegate. You can use the information passed in to show a native alert using UIAlertController.

iOS how to know if the html5 button was clicked loaded on an UIWebView

I have an iOS app with an UIWebView, and I need to receive a href url from server side and then present the web page which is a HTML5 from that href in my UIWebView:
MyViewController *myVC = [[MyViewController alloc] init];
myVC.url = serverSideResponse.href;
[self.navigationController presentViewController:myVC animated:YES completion:nil];
In the MyViewController.m, I have this:
_webView = [[UIWebView alloc] initWithFrame:myFrame];
[self.view addSubView:_webView];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[_webView loadRequest:request];
So the web page is from server side and I want my iOS app/webview to know if the button was clicked on that page. To be more specific, if that button was clicked, then I shut my webview (meaning removeFromSuperView).
Now what I can see is that when I check the source code of that web page, I know the button id.
The url I received was: https://api.uber.com/v1/surge-confirmations/edbfdd9a-276b-4b85-b3f4-5a0c948a17fe. And when I was loading it in my web view, it has a button and when I clicked it nothing happened, only console logged the click event and the request was: https://api.uber.com/v1/surge-confirmations/edbfdd9a-276b-4b85-b3f4-5a0c948a17fe# <--there comes an extra #.
But when I put the url in my desktop browser to present it and click the button, it can redirect to the next url (https://www.uber.com) as expected.
Please advise, thanks!
Thanks to #Wain and #palme, I found one of the UIWebView delegate callback methods
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
can do this.
Parameter request and navigationType can tell you what navigationType triggered what request.

UIWebview tripadvisor redirection bug to their app?

Recently I just discovered a little issue.
I'm using UIWebview to load some url some times nothing really fancy, just basic init:
self.webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, navBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-navBar.frame.size.height)];
self.webview.opaque = NO;
self.webview.delegate = self;
self.webview.scalesPageToFit = YES;
[self.view addSubview:self.webview];
and i'm loading the url like this:
if(self.webview)
{
[self.webview loadRequest:[NSURLRequest requestWithURL:url]];
}
The problem that i got is when i try to redirect to tripadvisor mobile page I got a pop up saying that my version is not handled anymore and that i need to update it, the thing is that even with the last update it doesnt work...
And it's the same for ios6, 7 and 8 and only for IPHONE ...
Is there anybody who got the same problem ? and maybe fixed it ?
Thanks !
Here is the image of the popup:
I just solved by change UIWebView's user-agent
NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:#"Safari iOS 8.0 - iPhone", #"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
put it before your webview initialize.
Hope this helps.

Feed list of URL´s from a Button to WebView XCODE 4.5

Good morning.
I´m trying to develop a small app, and I need some help...
I need to pass a URL from a button to a WebView. I have 4 buttons, when I choose BT1 it will open a WebView with url=www.google.com, when i choose BT2 it will open the same webview but with a different url (www.apple.com).
Thank´s for your help.
don't forget to assign the actions to the buttons & implementing UIWebViewDelegate in your ViewController...
-(IBAction)button1Clicked:(id)sender{
[self loadWebViewWithURL:#"http://www.google.com"];
}
-(IBAction)button2Clicked:(id)sender{
[self loadWebViewWithURL:#"http://www.apple.com"];
}
-(IBAction)button3Clicked:(id)sender{
[self loadWebViewWithURL:#"http://www.yahoo.com"];
}
-(IBAction)button4Clicked:(id)sender{
[self loadWebViewWithURL:#"http://www.microsoft.com"];
}
-(void)loadWebViewWithURL:(NSString*)urlstr{
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlstr] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:30.0f];
[myWebView loadRequest:request];
}

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?

Resources