WKWebView can not load url of flash message - ios

WKWebView *wb = [WKWebView new];
[wb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://file8a445fb7811e.iamh5.cn/v3/idea/u5UfsotV?suid=ohAJ7wa8J4S-rj0SFOVmrDhOBotM&from=singlemessage"]]];
This urlStr is a flash URL. It stops after load 99%. How do I fix it?
I tried to use UIWebview, it worked perfectly, but WKWebView not.

Related

UIWebView doesn't loadRequest second time

From firstViewController I send a url to load on secondViewController. The url loads correctly. They, I press cancel button to go back to firstViewController:
[self dismissViewControllerAnimated:YES completion:nil];
Then again if I come back to secondViewController from firstViewController, I see a blank space with horizontal scrollbar.
I've used the following code to load url:
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.myWebView loadRequest:requestObj];
I've implemented webview delegate methods and they are being called without any problem. for example following methods are called:
– webViewDidStartLoad:
– webViewDidFinishLoad:
Even there is no error to load and I've printed html source codes in -webViewDidFinishLoad and it Logged right codes.
My device iOS version is: iOS 9.3.2
Update:
The same app works well on my simulator. But doesn't work on real device.

how can I clear the contents of a UIWebView/WKWebView?

I have a webview that can be cycled through different URLs. When I switch from one to the other I want the old web page to disappear before loading the next one. How can I do this without re allocating the webview?
If I try to [self.webView loadHTMLString:#"" baseURL:nil]; and load my URL in the same function the previous web page still remains:
[self.webView loadHTMLString:#"" baseURL:nil];
[self.webView loadRequest:[NSURLRequest requestWithURL:self.pageURL]];
EDIT: this apparently isn't clear enough for you. the below code doesn't clear the webview, it displays the previous page until the new one is loaded:
- (void) startLoadOfNextURL:(NSURL*)url
{
// clear:
[self.webView loadHTMLString:#"" baseURL:nil]; //DOESNT WORK
// Load real next URL
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
You can write the code below while your controller dismisses.
webView.load(URLRequest(url: URL(string:"about:blank")!))
You can make it load a blank page
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
Use JavaScript instead.
webView.evaluateJavaScript("document.body.remove()")
The following code clears the screen and then navigates
Swift
webView.evaluateJavaScript("document.documentElement.remove()") { (_, _) in
self.webView.load(urlRequest)
}
To clear old contents of webview
When you call - loadHTMLString:baseURL: it doesn't block until the load is complete. Once it records your request, it returns and loads in the background.
As a result, you would need to wait for the first load to finish before kicking off a new load request.
With UIWebView you would use UIWebViewDelegate's
- webViewDidFinishLoad:.
With WKWebView you would use WKNavigationDelegate's
- webView:didFinishNavigation:
Another approach if you really wanted to clear the contents without a delegate method would be to use JavaScript (eg https://stackoverflow.com/a/4241420/3352624). Then for UIWebView you could invoke - stringByEvaluatingJavaScriptFromString:. That method will block execution until the JavaScript executes and returns.
For WKWebView, you would need to do something like https://stackoverflow.com/a/30894786/3352624 since its - evaluateJavaScript:completionHandler: doesn't block.
To make old contents "disappear"
If you really just want to make "the old web page to disappear", you could cover the content area of the webview with a blank UIView temporarily. You could hide the contents when you initiate the load and then show the contents using the delegate methods above after the load completes.
Swift
webView.load(URLRequest(url: URL(string: "about:blank")!))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: {
//Load request or write code here
})

Internet Connection Check UIWebView?

I have a UIWebView that loads a PDF document, like this:
NSURL *myUrl = [NSURL URLWithString:#"http://www.site.com/myPDF.pdf"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
// Clear Cache, to insure prompt update of PDF
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:myRequest];
[myWebView loadRequest:myRequest];
When my internet connection is off, i get nothing. Just a blank UIView. Is there any way i can detect when there is not internet connection, or check if the URLContents is empty? I am trying to call a method -(void)showErrorText to show text in the center screen. How would i do this? (I got the method complete, just not the internet check). THANKS.
You can try to set the delegate of the webView to self and implements the webView:didFailLoadWithError and the others delagate methods tout have more details.

Load WebView as soon as app starts

I have a WebView in my app that works fine but very slow to load. Is there a way to actually start loading the web view as soon as the app starts?
Thanks
[EconCalWebView setDelegate:self];
// Do any additional setup after loading the view.
NSURL *myURL = [NSURL URLWithString:#"http://www.forexyard.com/en/calendar.iframe?zone_id=9493"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[EconCalWebView loadRequest:myRequest];
You can write your code for loading webview in:
applicationDidFinishLaunching method available in AppDelegate Class.
Here you require to load your viewController first and then load webView.
Please find more details at : UIApplicationDelegate

How to force Vimeo player to play inline using UIWebView?

I am using following code to display Vimeo player in UIWebView:
_webView.delegate = self;
_webView.allowsInlineMediaPlayback = YES;
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://player.vimeo.com/video/12536488"]]];
Now when I'm clicking play button, native iPhone movie player appears.
How to enable inline playback?
What I already was trying to do is to get acces to video element after page is loaded to set webkit-playsinline attribute. I wrote:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[_webView stringByEvaluatingJavaScriptFromString:#"var video = document.getElementsByTagName('video')[0];"];
}
But video variable appears to be undefined.
Any ideas would be appreciated.
After all we decided to use paid account. Vimeo provides direct links for videos stored on "Pro" accounts.

Resources