zoukankan      html  css  js  c++  java
  • HTML调用Swift

    1. //UIWebView的代理方法拦截

       func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {self.perform(ViewController.Semethodscheme(request: request))

            return true

        }

    2.//解析协议
        static  func Semethodscheme(request: URLRequest) ->(Selector){

            let urlString: String = request.url!.absoluteString

            print("icocos:///urlString",urlString)

            var scheme: String = "icocos:///"

            //取出scheme后边的路径

                print("icocos:///scheme",scheme)

            if urlString.hasPrefix(scheme) {

                let path: String =  urlString.substring(from: scheme.characters.endIndex)

                print("icocos:///path",path)

                let array: [Any] = path.components(separatedBy: "?")

                print("icocos:///array",array)

                Tunarr = array

                let methodName: String? = (array.first as! String)

                print("icocos:///methodName",methodName as Any)

                let Semethod: Selector = NSSelectorFromString(methodName!)

                print("icocos:///Semethod",Semethod)

                 return Semethod

            }

          return NSSelectorFromString("SelectorFromString")

        }

    3.//调用方法

    func Tuneup(){

            let tune =

            ViewController.Tuneupurl()

           if  tune == "addent"{

           }else if tune == "follow"{

          }

        }

    4.//区分方法(你和后台定的规则我怎么会知道这是我的逻辑)

     static func Tuneupurl() ->(String){

        if  Tunarr?.count != 0{

        let rawJson = JSON(Tunarr![1]).rawString(String.Encoding.utf8, options: .prettyPrinted)

        let rawJsonurl = rawJson?.urlDecoded()

        let jsonDict = try? JSONSerialization.jsonObject(with: (rawJsonurl?.data(using:.utf8))!, options: .mutableLeaves)

        guard let  Tunedic = jsonDict as?[String: String], let Tune = Tunedic["Tuneupurl"] else{return ""}

            return Tune

            }

            return ""

        }

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    jdbc连接池中c3p0的配置文件的详解以及在在java中如何使用
    idea导入myeclipes项目、运行项目
    java中身份证号和的银行卡的深度校验
    springBoot的搭建使用记录
    java分模块项目在idea中使用maven打包失败(ps:maven常用到的命令)
    js获取当前页面相关信息
    mybatis使用中的记录
    tomcat服务的启动与隐藏启动(win)
    cmd命令关闭占用程序的端口
    ping端口是否开放(windows,macos,linux)
  • 原文地址:https://www.cnblogs.com/Jusive/p/7743581.html
Copyright © 2011-2022 走看看