iframe 未在 WKWebview 中加载

Posted

技术标签:

【中文标题】iframe 未在 WKWebview 中加载【英文标题】:iframe doesnot loading in WKWebview 【发布时间】:2020-04-09 06:29:40 【问题描述】:

我使用 wkwebview 显示其中包含 iframe 的网络内容,但我的静态数据显示在其中,但 iframe 未显示。我使用了 loadhtmlstring 方法,因为 loadrequest 在 post 方法中不起作用。我在下面添加了我的代码,请帮助

let parameters: [String: Any] = ["amount":"378.0","customer_id":"1000","reference_id":"123456","customer_email":"123.s@gmail.com","customer_mobile":"1111111","customer_name":"cust","address":"add"]

        let headers = ["Content-Type": "application/json"]
    Alamofire.request(Constant.sharedInstance().baseUrl+"online_payment"+Constant.sharedInstance().wsUrl, method:.post, parameters: parameters, encoding: JSONEncoding.default,headers: headers)
        .responseJSON  response in


            if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) 
                print("Data: \(utf8Text)")
                var urlRequest = URLRequest(url:URL(string: Constant.sharedInstance().baseUrl+"online_payment"+Constant.sharedInstance().wsUrl)! )


                urlRequest.httpMethod = "POST"
                self.webView.loadHTMLString(utf8Text, baseURL: nil)

                //self.webView.load(urlRequest)
            
            else
            
                let dic = ["message":"Something went wrong, Please try again"]



            

    

【问题讨论】:

***.com/questions/44676297/… 【参考方案1】:

我终于得到了答案。只是身体的问题。

如果以后有需要,我会在下面发布我的代码


    let urlAsString = Constant().baseUrl+"online_payment"+Constant().wsUrl
    let url: NSURL = NSURL(string: urlAsString)!
    let request = NSMutableURLRequest(url: url as URL)
    request.httpMethod = "POST"
    request.addValue("application/json", forHTTPHeaderField: "content-type")



           var parameters: [String: Any]? = nil


          if((UserDefaults.standard.value(forKey:"userDetails")) != nil)
               let userDetail:NSDictionary = UserDefaults.standard.value(forKey: "userDetails") as! NSDictionary
            name = userDetail.value(forKey: "name") as? String
            mobile = userDetail.value(forKey: "phone") as? String
            customer_id = userDetail.value(forKey: "user_id") as? String
            email = userDetail.value(forKey: "email") as? String


         
    if(reference_id == nil || reference_id == "")
        if(appData.bookingDetailDic["reference_id"] == nil)
           reference_id = ""
        
        else
           reference_id =  appData.bookingDetailDic["reference_id"] as? String
        


        date = appData.bookingDetailDic["selectDate"] as? String
        total = appData.bookingDetailDic["displayTotal"] as? String
        address = appData.bookingDetailDic["address"] as? String
    else if(reference_id != nil)
        appData.bookingDetailDic["reference_id"] = reference_id
        appData.bookingDetailDic["displayTotal"] = total
        appData.bookingDetailDic["address"] = address
        appData.bookingDetailDic["selectDate"] = date

    

                       parameters = ["amount":"\(String(describing: total!))","customer_id":"\(String(describing: customer_id!))","reference_id":"\(String(describing: reference_id!))","customer_email":"\(String(describing: email!))","customer_mobile":"\(String(describing: mobile!))","customer_name":"\(String(describing: name!))","address":"\(String(describing: address!))"]
    print(parameters as Any)

    do 

        let jsonData = try JSONSerialization.data(withJSONObject: parameters as Any, options: [])
        request.httpBody = jsonData

     catch
    
        print("error writing JSON: \(error)")
    

    webView.load(request as URLRequest)


【讨论】:

以上是关于iframe 未在 WKWebview 中加载的主要内容,如果未能解决你的问题,请参考以下文章

来自html字符串的iOS Swift 4图像未在WKWebView中加载

iFrame 未在 Flex 弹出窗口中加载

iframe 未在 Jquery 中加载

iFrame 未在 FireFox 的选项卡中加载

Javascript iframe 未在引导弹出窗口中加载(模式)

Python Shopify应用程序未在Safari iframe中加载