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

        }

    挥毫泼墨,书写人生篇章
  • 相关阅读:
    ImageView的属性android:scaleType
    Java容器类List、ArrayList、Vector及map、HashTable、HashMap分别的区别. (转)
    Pro Andorid3第一章:Android平台简介
    Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
    归纳法(induction)
    dual graph
    Project和编程过程
    维度
    dos
    关于glfrustum与hemicube的真实长度的关系
  • 原文地址:https://www.cnblogs.com/Jusive/p/7743581.html
Copyright © 2011-2022 走看看