iOSHTML5的JS交互-创新互联

 //webView与H5点击交互走的代理

创新互联公司主营平川网站建设的网络公司,主营网站建设方案,app软件开发公司,平川h5小程序定制开发搭建,平川网站营销推广欢迎平川等地区企业咨询

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

{

   NSURL * url = [request URL];

   NSString * urlStr = url.absoluteString;

   NSString * protocolPrefix = @"scheme";//和后台定义好的字符

   [self H5Js:protocolPrefix url:urlStr];

   return YES;

}

//数组分离参数 开始进行关键字提取以及相关操作

-(void)H5Js:(NSString *)protocolPrefix url:(NSString *)urlStr

{

   if ([[urlStr lowercaseString]hasPrefix:protocolPrefix])

   {

       urlStr = [urlStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

       NSArray * components = [urlStr componentsSeparatedByString:@":"];//以":"截取字符

       NSArray * shareUrl = [urlStr componentsSeparatedByString:@"?"];

//       NSLog(@"%@",components);

       NSString * prefix = components[1];

       if ([prefix isEqualToString:@"awardLogin"])

       {

           isReash = YES;

           [self jumpLogin];

       }

       if ([prefix isEqualToString:@"awardBindMobile"])

       {

           //绑定手机

           ModifyPhoneController * phone = [[ModifyPhoneController alloc]init];

               phone.title=@"绑定手机";

           [self.navigationController pushViewController:phone animated:YES];

       }

       if([prefix rangeOfString:@"awardShare"].location !=NSNotFound)

       {

           NSRange range1 = [urlStr rangeOfString:@"?"];//匹配得到的下标

           //       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:@"="];//匹配得到的下标

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

           NSString *rangeStr1 =[parameter[4] substringFromIndex:range.location+1];

           [dic setObject:rangeStr1 forKey:@"smsContent"];

            [self share:nil];

       }

   }

}

//回调JS代码

 NSString * str =[NSString stringWithFormat:@"lsf_login_callback(%@)",[User shareUser].userId];

       //评论完后刷新html5 页面

       [self.webView stringByEvaluatingJavaScriptFromString:str];

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:iOSHTML5的JS交互-创新互联
新闻来源:http://pwwzsj.com/article/coppgd.html