适用于IOS版本12.4.8但不适用于13.6.1的IOS App

时间:2020-08-28 13:16:14

标签: swift soap

希望你们能提供帮助。我有一个应用程序,该应用程序从可在iPhone 6(V12.4.8)上运行的公司Windows服务器下载文件,但在iPhone 8(V13.6.1)上崩溃。我一直在尝试找出为什么没有成功的原因。您提供的任何帮助将不胜感激。应用程序崩溃显示-

***由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“从主线程访问布局引擎后,不得从后台线程对其进行修改。”

这是它失败的功能.....从警报控制器调用:

    func DownloadFile(Path: String, DocName: String){
    let DocName2 = DocName.replacingOccurrences(of: " ", with: "_")
    ParseAllData = true
    is_SoapMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><DownloadFile xmlns=\"LSM_Multiservices\"><Username>\(GlobalStart.Username)</Username><Password>\(GlobalStart.Password)</Password><DocName>\(DocName2)</DocName><FullPath>\(Path)</FullPath></DownloadFile></soap:Body></soap:Envelope>"
    
    print(DocName)
    print(Path)
    
    let URL: String = GlobalSettings.ServerAddress
    let WebRequ = NSMutableURLRequest(url: NSURL(string: URL)! as URL)
    WebRequ.httpMethod = "POST"
    WebRequ.httpBody = is_SoapMessage.data(using: String.Encoding.utf8)
    WebRequ.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
    WebRequ.addValue(String(is_SoapMessage), forHTTPHeaderField: "Content-Length")
    var Str: String = ""
    
    let task = session.dataTask(with: WebRequ as URLRequest, completionHandler: {data, response, error -> Void in
        if data.self == nil{
            //self.CustomAlert(Message: "LSM Multiservices", Information: "Failed to contact server. Please try again.")
            self.ClearTasks()
            return
        }
        let strData = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
        Str = String(strData!) as String
        Str = Str.replacingOccurrences(of: "&lt;", with: "<")
        Str = Str.replacingOccurrences(of: "&gt;", with: ">")
        Str = Str.replacingOccurrences(of: "&amp;", with: "&")
        Str = Str.replacingOccurrences(of: "Invoice_No ", with: "Invoice_No")
        print(Str)
        print(Path)
        GlobalPRViewRecord.XMLData = Data(Str.utf8)
        
        
        if error != nil
        {
            print("Error: " + error.debugDescription)
        }
    })
    task.resume()
}

1 个答案:

答案 0 :(得分:0)

所有修改UI的代码应在UI线程中完成 我想你的情况就是这样

//self.CustomAlert(Message: "LSM Multiservices", Information: "Failed to 
       contact server. Please try again.")
        self.ClearTasks()

将其包装到主队列中

 DispatchQueue.main.async {
   //self.CustomAlert(Message: "LSM Multiservices", Information: "Failed to 
           contact server. Please try again.")
            self.ClearTasks()
}