JS interaction with IOS HTML5

Source: Internet
Author: User

//webview with the H5 Click the Interactive walk Agent   

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

{

Nsurl * url = [request URL];

NSString * urlstr = url.absolutestring;

NSString * Protocolprefix = @ "scheme";// and background-defined characters


[Self h5js:protocolprefix url:urlstr];


return YES;

}


// Array Separation Parameters get started with keyword extraction and related actions

-(void) H5js: (NSString *) protocolprefix URL: (NSString *) urlstr

{

if ([[Urlstr Lowercasestring]hasprefix:protocolprefix])

{

URLSTR = [Urlstr stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding];

Nsarray * components = [Urlstr componentsseparatedbystring:@ ":"];// with ":" intercepts characters


Nsarray * Shareurl = [urlstr componentsseparatedbystring:@ "?"];




NSLog (@ "%@", components);


NSString * prefix = components[1];


if ([prefix isequaltostring:@ "Awardlogin"])

{

Isreash = YES;

[Self jumplogin];

}

if ([prefix isequaltostring:@ "Awardbindmobile"])

{

Binding Phone

Modifyphonecontroller * Phone = [[Modifyphonecontroller alloc]init];

[Email protected] " bind phone ";

[Self.navigationcontroller Pushviewcontroller:phone Animated:yes];


}


if ([prefix rangeofstring:@ "awardshare"].location!=nsnotfound)

{

Nsrange Range1 = [Urlstr rangeofstring:@ "?"];/ / match the resulting subscript

NSLog (@ "rang:%@", Nsstringfromrange (range));

NSString *rangestr =[urlstr substringfromindex:range1.location+1];

Nsarray * parameter = [rangestr componentsseparatedbystring:@ "&"];

NSLog (@ "%@", parameter);

[DiC setobject:[parameter[1] componentsseparatedbystring:@ "="][1] forkey:@ "Sharetitle"];

[DiC setobject:[parameter[2] componentsseparatedbystring:@ "="][1] forkey:@ "sharecontent"];

[DiC setobject:[parameter[0] componentsseparatedbystring:@ "="][1] forkey:@ "shareimg"];

[DiC setobject:[parameter[3] componentsseparatedbystring:@ "="][1] forkey:@ "Shareurl"];


Nsrange range = [Parameter[4] rangeofstring:@ "="];// match the resulting subscript

NSLog (@ "rang:%@", Nsstringfromrange (range));

NSString *rangestr1 =[parameter[4] substringfromindex:range.location+1];


[DiC setobject:rangestr1 forkey:@ "Smscontent"];


[Self share:nil];

}

}

}



// Callback JS Code

NSString * Str =[nsstring stringwithformat:@ "Lsf_login_callback (%@)", [User Shareuser].userid];

Refresh The HTML5 page after the comment is finished

[Self.webview STRINGBYEVALUATINGJAVASCRIPTFROMSTRING:STR];


This article is from the "zhuoking" blog, make sure to keep this source http://9951038.blog.51cto.com/9941038/1842724

JS interaction with IOS HTML5

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.