iOS HTML5的JS交互

发布时间:2020-08-10 13:26:56 作者:卓行天下
来源:网络 阅读:517

 //webViewH5点击交互走的代理  

-(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];


推荐阅读:
  1. WebViewJavascriptBridge实现js与android和ios原生交互
  2. IOS JS 交互

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

html request j

上一篇:oracle安装后完善2-2 如何像Linux 命令行一样可以上下键翻历史命令

下一篇:Feeding Vertex Shaders from Buffers从缓冲区给shader输入数据

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》