Google Login with GIDSignIn didn't have back button - ios

I used the GPPSignIn to login google in the first time.
But it's rejected by App Store because it will open the Safari when login
So I replace the GPPSignIn with GIDSignIn.
And it works! It can login with WebView!
But the question is.... how should I back when I open the WebView!
Or say how should add the "Back Button" in this WebView
Thanks for your helping :)

You can Try html markup such as My Button into the content of your UIWebview using stringByEvaluatingJavaScriptFromString method.
To capture the click event and prevent it from reloading content of your webview use this delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if(navigationType==UIWebViewNavigationTypeLinkClicked && [[request.URL absoluteString] isEqualToString: #"yourTag01"])
{
//your action code goes here
return NO;
}
return YES;
}
For Action of your button You can use this :
if ([yourWebView canGoBack])
{
[yourWebView goBack];
}

I recently had a similar problem. I solved it with import libraries SafariServices.framework and run app again.
http://i.stack.imgur.com/eonwU.png

Related

YTPlayerView once loaded opens the video in youtube app

So the title pretty much sums up the situation I am loading my YTPlayerView like this:
[self.videoView loadWithVideoId:#"youtube id"];
And like it was mentioned in the documentation it works perfectly however the second time I tap on the view the video opens on the youtube app sometimes and not on fullscreen.
Any help here ?
After a lot of research I didn't find an answer to this question so I decided to dig on the YTPlayerView.m file and see how the touch event is handled and I found that there is two ways to do this:
1- the YTPlayerView contains a webView and an override of:
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
This is the full code which checks the url scheme to trigger the appropriate action
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
if ([request.URL.host isEqual: self.originURL.host]) {
return YES;
} else if ([request.URL.scheme isEqual:#"ytplayer"]) {
[self notifyDelegateOfYouTubeCallbackUrl:request.URL];
return NO;
} else if ([request.URL.scheme isEqual: #"http"] || [request.URL.scheme isEqual:#"https"]) {
return [self handleHttpNavigationToUrl:request.URL];
}
return YES;
}
which was in my case this function handleHttpNavigationToUrl that returns a bool which indicates if the video should open on the app or the youtube application.
I have commented these lines that opens the video on the app and everything is ok now.
[[UIApplication sharedApplication] openURL:url];
return NO;
This is a quick fix and not good one i know but in my case i had no choice the 2nd solution is much better though.
2- The problem is in the youtube url in the first place as if you are using the embed url this problem will not occur,
so instead try to use other methods for loading the video by using the embed url, which is of the format:
http(s)://www.youtube.com/embed/[VIDEO ID]?[PARAMETERS]
so just try to use loadVideoByURL and use the embed url instead of loadWithVideoId.
Voila i hope this helps.

Prevent user from selecting a link on a UIWebView page

I have a UIWebView successfully loading and displaying a page. However, I don't want the user to leave the page. I have tried setting User Interaction Enabled = NO, but that disable scrolling too. How can I make the page so when pressing a link it won't leave the page?
Implement this method, and return NO
webView:shouldStartLoadWithRequest:navigationType:
That will prevent the user from viewing anything but that single page.
Update:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
return NO;
}
return YES;
}

Is it possible to intercept the click handler in links of WEBUI's, and add a custom click action?

Say there's a custom link embedded in a WebUIView, and I would want to redirect a user not to Safari but to a different screen in the app. Is it possible to change the click handler for that link?
You can assign a delegate to the webView and use the webView:shouldStartLoadWithRequest:navigationType: method to detect the links you want a return NO.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[request.URL absoluteString] isEqualToString:#"http://www.customurl.com"]) {
// Do something
return NO;
} else {
return YES;
}
}
You may also want to check the navigationType against UIWebViewNavigationTypeLinkClicked.

How to hide uiwebview navigation buttons

I have a UIWebView that I use to load a webpage. I also have navigation buttons so you can go back and forward between previous pages loaded. Is there a way to hide the navigation buttons when there is no previous webpage?
Check here: Why is UIWebView canGoBack=NO in iOS7?
You can enable/disable your navigation buttons in the shouldStartLoadWithRequest method with canGoBack and canGoForward methods on UIWebView:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if ([webView canGoBack])
{
[_browserBackItem setEnabled:YES];
}
else
{
[_browserBackItem setEnabled:NO];
}
if ([webView canGoForward])
{
[_browserForwardItem setEnabled:YES];
}
else
{
[_browserForwardItem setEnabled:NO];
}
return YES;
}
I'm not aware of anything built in to UIWebView that allows this but maybe you could try keeping track of the pages with a variable.
Every time a url request is made the UIWebView delegate method gets called and you could increment the variable there (see here). Then decrement the variable once the user has selected the back button.
Hope that helps.
you can save the loaded pages in an NSArray for example and test if that array is empty you hide the button.
to know the opened pages, you implement the UIWebViewDelegate in your class, and in the – webView:shouldStartLoadWithRequest:navigationType: callback you save the url.

Switch to next view with UIWebView

When you use the Facebook App and go to the Terms and Conditions view, there is a WebView. When you choose an option in the WebView you'll go to a new view.
Now I wanna make a login system with PHP. When the user login is succeded he'll go to an webpage. How can I set for example: When the UIWebView is on www.myserver.com/ok that the new view in my app will show?
Set your UIWebView with delegate and check :-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"Loading: %#", [request URL]); //if url matches www.myserver.com/ok open your view
return YES;
}
Hope it helps you..

Resources