iOS development: How to call iOS with JS

Source: Internet
Author: User

this article reprinted to: Http://blog.chinaunix.net/uid-29415710-id-4058564.html

-(BOOL) WebView: (UIWebView *) WebView shouldstartloadwithrequest: (nsurlrequest *) Request Navigationtype: ( Uiwebviewnavigationtype) Navigationtype {

Nsurl * url = [request URL];

if ([[[URL scheme] isequaltostring:@ "AAA"]) {

Nsarray * Separatedarray = [[Nsarray alloc]init];

Nsmutablearray *temp = [[Nsmutablearray alloc] init];

Separatedarray = [[[url absolutestring] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding] Componentsseparatedbystring:@ ","];

[Temp Addobjectsfromarray:separatedarray];

NSLog (@ "code1__%@:", [[url absolutestring] stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding]);

NSLog (@ "Url__scheme%@", [url absolutestring]);

Self.taskdownloader = [[Multitaskdownloader alloc] init];

Taskdownloader.delegate = self;

for (int i = 0; i < separatedarray.count-1; i++) {

Nsarray *filenames = [[Separatedarray objectatindex:i] componentsseparatedbystring:@ "^"];

NSString * FileName = [FileNames lastobject];

NSLog (@ "ABC---%@", fileName);

[Temp replaceobjectatindex:i withobject:filename];

[Taskdownloader Addtaskurl:[[[separatedarray objectatindex:separatedarray.count-1] stringByAppendingString: @ "/ Files/"] stringbyappendingstring:[filename stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];

[Taskdownloader Addtaskfielname:filename];

NSLog (@ "Filename--00-%ld", (long) separatedarray.count);

}

[Taskdownloader start];

return NO;

}

Above is the main code in iOS. is to intercept the URL. According to what is intercepted. Perform the corresponding judgment.

function Loadurl (URL) {

var iFrame;

iframe = document.createelement ("iframe");

Iframe.setattribute ("src", url);

Iframe.setattribute ("Style", "display:none;");

Iframe.setattribute ("height", "0px");

Iframe.setattribute ("width", "0px");

Iframe.setattribute ("frameborder", "0");

Document.body.appendChild (IFrame);

This iframe is useless after initiating a request, so remove it from the DOM.

IFrame.parentNode.removeChild (IFrame);

IFrame = null;

}

After that, it's how to send the URL. Very simple. Look at the code above yourself. It's like this when you want to use it:

Loadurl ("AAAA:"));

This way, you can intercept the AAAA on iOS.

And then. It's what you want to do after you intercept.

The code is simple. Let's see. In addition, for iOS development, it is recommended that novice look at the iOS API more. A simple function, people who are not familiar with the API will have to pay a great deal of effort to achieve, and in fact, with the API a word can be solved. This is not familiar to the API is easy to detour.

For more information on iOS development , check out Heaven http://ios.9tech.cn/

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.