访次: AmazingCounters.com 次

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

    }

挥毫泼墨,书写人生篇章
posted @ 2017-10-27 15:31  JusDoit  阅读(386)  评论(0编辑  收藏  举报