Xcode6 UIWebView and JavaScript interaction (issue fix), xcode6uiwebview

Source: Internet
Author: User

Xcode6 UIWebView and JavaScript interaction (issue fix), xcode6uiwebview

This article describes the interaction between UIWebView and JavaScript. In UIWebView, JavaScript request processing is intercepted. From the app perspective, this is a JavaScript Hook request.

In App versions earlier than Xcode6, JavaScript can send Hook requests as follows:

HTML:

<li><a href="testapp://function=test&callbackJS=testCallback">test link</a></li>
JavaScript:

<script language="JavaScript" type="text/javascript">  function xcode6(){var url = apptest://function=test&callbackJS=testCallback;location.href = url;  }</script><li><a href="Javascript:xcode6();">Xcode6 Javascript</a></li>


In the Xcode6 App, it is found that the href method changed through JavaScript is unavailable. From the app perspective, (BOOL) webView :( UIWebView *) webView shouldStartLoadWithRequest :( NSURLRequest *) request navigationType :( UIWebViewNavigationType) navigationType is not called.


Solve this problem through escape URL:

<script language="JavaScript" type="text/javascript">  function xcode6(){var url = 'apptest://'+escape('function=test&callbackJS=testCallback');location.href = url;  }</script><li><a href="Javascript:xcode6();">Xcode6 Javascript</a></li>






For ios UIWebView, how does javascript call system services?

The most common interaction method in ios is to implement webview through URL Scheme. shouldStartLoadWithRequest :( NSURLRequest *) request navigationType :( UIWebViewNavigationType) navigationType can be used to process various URL Scheme. For example:-(BOOL) webView :( UIWebView *) webView shouldStartLoadWithRequest :( NSURLRequest *) request navigationType :( UIWebViewNavigationType) navigationType {
NSLog (@ "shouldStartLoadWithRequest called ");
NSURL * url = [request URL];
If (! [[Url scheme] isw.tostring: CUSTOM_PROTOCOL_SCHEME]) {
Return YES;} NSString * actionType = [url host];
If ([actionType ispolictostring: @ "alert"]) {
NSLog (@ "alert called ");
NSString * JSONString = [
[[Url fragment] stringByReplacingOccurrencesOfString: @ "+" withString: @ ""] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
[[IToast makeText: NSLocalizedString (JSONString, @ "")] show];} return NO;} in this way, you can: var url = schema + ": // alert "+" # "+ encodeURIComponent (msg );
Document. location = url; call object c to update in the opposite direction:

UIWebView has one problem.

It is difficult to make it clear. Because most 3000 boards can be saved before they have to be charged, once the power is off, the motherboard will automatically restore a real country that won't recognize your pirated game. This is normal. Generally, the sales host owner can crack the software (Real System Identification and operation of the signature) during the running time and identify the game. However, you also said, it is unclear how you and your brothers click it. Said, when you buy a machine, the boss God, instead of disturbing your account on your machine, such training and preparation, then you throw the money to the boss to stay? Did not communicate with each other?
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.