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 ""

        }

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    删除linux系统中的eth0.bak与多余的网卡 枯木
    linux下netstat详解 枯木
    世事无常中渐渐长大 枯木
    Redhat enterprise linux6.0的yum源配置 枯木
    yum的常用命令 枯木
    AWStats简介:Apache/Windows IIS的日志分析工具的下载,安装,配置样例和使用(含6.9中文定义补丁) 枯木
    shell简单管理iptables脚本 枯木
    RHEL6 下Cfengine V3 安装测试1 枯木
    存储过程事务
    C#加密方法汇总
  • 原文地址:https://www.cnblogs.com/Jusive/p/7743581.html
Copyright © 2011-2022 走看看