iOS WebView url with javascript - ios

In Android, app can change webview's url with "javascript:alert(123);",
then webview will alert 123.
I want to know is it can work in ios app ?

Yes.
Use this function stringByEvaluatingJavaScriptFromString. Read more about this function at UIWebView class reference
[webView stringByEvaluatingJavaScriptFromString:#"alert('123');"];
Hope this is what you are looking for.
P.S.: Use this function once webViewDidFinishLoad is called.

Yes.
Here is a great article: True JavaScript+UIWebView integration in iOS7 - http://blog.impathic.com/post/64171814244/true-javascript-uiwebview-integration-in-ios7

Related

What is the equvalent of "OnUserInteraction" in iOS

I want to know if there is any android "OnUserInteraction" equvalent in iOS. I want to implement session logout functionality so I need to know any equvalent functionality fo OnUserInteraction.
In iOS you can subclass UIApplication and override SendEvent as outlined here.

How can a I use the window.print method in a WebView with react-native

I'm using react-native and its webview to call a webpage where at the end of a flow of four or five pages, they use the window.print method to print the page. But, when I tap the button to print the page nothing happens. Do you know what can I do in this situation to make the button work?. I've only tried this in Android and I use "react-native-webview": "^5.10.0" with "react-native": "^0.59.9".
I am using a work around for now as my react native webview app only consists of the uri of the web app. What I am doing is I am checking if window.ReactNativeWebView exists or not. If yes, then do window.ReactNativeWebView.print() so for my app it takes me to the external browser of that device and there since window.ReactNativeWebView doesn't exists, I do window.print().
I am not sure if this is the right way to do but if someone has a better solution. I am eagerly waiting for it!

Is there a function in ios webview like setCacheMode in android webview?

What feature should I use to allow iOS Webview's web content to be cached only for in the expired time in the server's meta data? I can't find keywords.
In Android Webview I solved it with setCacheMode (default).
Please WBWebKit instead of Webview.
it will give you access for cache setting using the following code:
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);

Auto refresh UIwebview issue in ios?

I have developed an app in which I load the data into webView. My webpage refresh in every 5 seconds through an ajax call. It is working fine in android. Rendering of page in android is very fast. It doesn't seem that url is reloaded in android but in iOS when page refreshing is very slow. Can anybody please tell me the solution?
Have you tried using WKWebView instead of UIWebView?
Please Refer to Is Safari on iOS 6 caching $.ajax results? link.
I think it will solve your problem if you do not allow cache data to load while refreshing UIWebView

iOS App: Replace Flash in webview with native player

I'm about to work on my first ever iOS app. For the first version, the main goal is to make the app a webview of my website. This is easy so far by just pointing a webview to the proper url. The part I need help with is replacing a Flash video player in the webview with a native video player.
Basically on the website I have a Flash video player that connects to a streaming video server with RTMP. As of now, the website is required to use Flash video (so converting to HTML5 video is not an option). The iOS app should show the website as is, except find the Flash player and replace it with a native video player so that the video playback still works on the iPhone/iPad.
Does anyone have any advice for accomplishing this?
This can be done. It may not be clean and pretty, but here is a possible approach: You are going to need to parse the HTML prior to displaying it.
First, you need to intercept the load request calls of your UIWebView so that you can check to see if it is calling the URL of the page that has the Flash you need to parse out. To intercept the load request call, use the UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType: to read the URL.
If the URL matches the URL you need to remove the Flash from, you are going to run code that loads a HTML string that you will parse into the web view (more on that in a minute) and return NO to the webView:shouldStartLoadWithRequest:navigationType: delegate method. This means that when the user tries to go to the page with the Flash in it, we are going to stop the UIWebView from doing its thing and load the view with our own parsed content.
Once you figure out that you need to parse the HTML, you need to get in into a variable that you can work with. To get the HTML of your page as a string:
NSURL *yourURL = [NSURL URLWithString:#"http://google.com"];
NSError *error;
NSString *htmlString = [NSString stringWithContentsOfURL:yourURL encoding:NSUTF8Encoding error:&error];
Once you have the string, to remove the Flash code from your HTML, see this question:
Comment out a string in HTML before UIWebView can display it
Once you have parsed the HTML and gotten rid of your Flash, you can load it into your web view with [webView loadHTMLString:string baseURL:nil];
Finally, you need to insert a native movie player on top of your web view via code. You'll have to deal with screen rotation and sizing and placement of the native player on top of the web view, but that fun I will leave to you.
That is a lot of raw material, but is should get you going on one on possible solution.
So, what you’re asking is to show a WebView inside the native app, and show some native components inside this WebView. This cannot be done.
You will have to build a completely native app for this. Or use HTML5 inside the WebView.

Resources