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..
Related
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
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;
}
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.
I have a ios program for iPad. It is used 2 view, A view has webview, another has imageview. When I returned webview from imageview, webview is opened homepage. I want to return last page . How can I do?
If I understand you correctly, you want to make sure, that the last page that was loaded in the UIWebView will be displayed again when you switch back to the UIWebView.
To achieve that you can keep track of the last URL that was loaded in the UIWebView. You can do that in the following UIWebViewDelegate method (declare currentURL as property):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.currentURL = request.URL;
return YES;
}
And then when you bring back your UIWebView:
- (void)showWebView {
[yourWebView loadRequest:[NSURLRequest requestWithURL:currentURL]];
}
"By clicking Register you are agreeing to our Terms and Conditions"
What is the easiest option to implement in the code where the entire above line is made clickable (this launches a modal view that shows the terms and conditions) AND the word "terms and conditions" is underlined in blue.
We tried various options.
1) We created a UIWebView and tried loading a html into it. But the html was rendered as is.
eg: "html body.../body html"
2) We tried to create a button with a label over it but we were not able to create a borderless button.
Thanks!
We were able to create the formatting by using a webView. We used one of the delegate of webView to complete the process. Here is sample code
NSString *html = #"<html><head><title>Terms and Conditions</title></head><body style=\"font-family:verdana;font-size:10px;\"><p>By clicking \"Register\" you are agreeing to our <b><u><font color=\"blue\">Terms and Conditions.</font></u></b></p></body></html>";
[termsWOutlet loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.google.com/message"]];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"%s",__FUNCTION__);
NSURL* u = [request URL];
if( [[u scheme] isEqualToString:#"showlicenses"] ) {
NSLog(#"in %s",__FUNCTION__);
[self performSegueWithIdentifier:#"loadTNC" sender:self];
return NO; // DO NOT attempt to load URL
}
return YES; // if you want to allow the URL to load
}