I am doing this inside my UIWebView delegate. I want to close current UIViewController and all opened UIViewControllers when the success web page finished its loading.
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"URL----------%#",webView.request.URL.path);
[self.actindi stopAnimating];
if ([webView.request.URL.path isEqualToString:#"/success.php"]) {
dm.isPaySuccesss=YES;
[self closeit];
}
}
When I debug this happens. But when I in my client's phone its not closing even the current view. Same OS version. mine is 6plus. His one is 6s.whats the reason for this? Please help me.
Thanks
remove view with this
[self.view removeFromSuperview];
Related
I use a local HTML file displayed in a UIWebview to display "Help" in my iPad app. The web view is embedded in another view which also has back and forward buttons linked to the goBack and goForward methods.The buttons work as expected in the iOS 10.2 simulator, but not in in the iOS 11 simulators. In iOS 11 when I tap on a link in the HTML file the link works, but the back button does not, despite the fact that canGoBack is true. Oddly enough the back button starts to work after I tap on a link that returns me to the top of the page. Is this an Apple bug or is there a workaround? My method:
-(IBAction)goBack:(id)sender {
NSLog(#"HVC in goBack canGoBack is %d", self.webView.canGoBack);
[self.webView goBack];
}
Output when the go back button does not work:
2017-11-10 09:32:41.752614-0700 MHRS[2436:151546] HVC in goBack canGoBack is 1
If your initial page in UIWebView is not remote page after clicking any link in this first page you will be redirected, but goBack method will became unavailable try this method it may work for you.
- (void) goBackToRederect {
if ([self.webView canGoBack]) {
[self.webView goBack];
} else {
[self.webView loadData:htmlData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:url];
} }
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 create a custom UIWebView for my project.now i load one website that UIWebView and also create two button like previous page and next page on top of navigation bar. i want to know how to handle the UIWebView pages,when i click the previous or next button.Those buttons handle the UIWebView pages.i need exact code for the those previous and next buttons.could any one help please. thanks in advance
Try this code to goForward and GoBack.
- (IBAction) buttonGoBack
{
if ([webView canGoBack])
{
[webView goBack];
}
}
- (IBAction) buttonGoForward
{
if ([webView canGoForward])
{
[webView goForward];
}
}
I'm using a Navigationcontroller which pushes a new Viewcontroller containing a Webview every time a link is clicked. One of the URLs has a javascript function, which calls another function every 60 seconds. It works fine, but when I hit the back button once after being on that web view (containing the javascript), the webview stays active and keeps doing the javascript calls, while going back to the previous webview flawlessly. I can see it doing things through NSLog. Why is that and how can I avoid this?
EDIT:
I have declared my subclass of UIWebView in my Viewcontroller like this:
#property (strong, nonatomic) AFXTWebView *wv;
and this is how I instantiate it (in ViewDidLoad):
[self setWv:[[AFXTWebView alloc] initWithVC:self andURLString:[self.pageConfig objectForKey:xAFXTPageLink]]];
[self.view addSubview:self.wv];
[self.wv loadWebView];
I have also tried setting the webView to nil in viewWillDisappear:
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.wv = nil;
}
You have to use the viewWillAppear & viewWillDisappear methods
-(void)viewWillAppear:(BOOL)animated
{
_webView=[[UIWebView alloc]init];
......//do your stuff
}
-(void)viewWillDisappear:(BOOL)animated
{
[_webView removeFromSuperView];
_webView=nil;
}
In your viewWillDisappear load a blank page into the web view.
This sounds like your web view and view controller are not being released, i.e. you have a leak. You should check your code for any unreleased retained/strong references to your view controller or web view.
-(void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
}
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.