gpt4 book ai didi

ios - 如何在调用 SOAP 网络服务时显示事件指示器?

转载 作者:行者123 更新时间:2023-11-30 11:24:15 26 4
gpt4 key购买 nike

他在那里,

我试图在用户点击登录按钮时显示事件指示器。我使用了有关如何显示事件指示器的教程,但没有任何效果。

我正在做的是,我有一个连接到 Microsoft SQL Server 的 SOAP Web 服务,并且我正在调用此 Web 服务来检查登录。我想在验证用户输入时显示事件指示器

这是按钮操作

@IBAction func loginButton(_ sender: Any) {
activityIndicator.startAnimating()

guard let usernametext = usernameTextfield.text, let passwordText = passwordTextfield.text else {
return
}

if usernametext.isEmpty || passwordText.isEmpty {
AlertMessage().showAlertMessage(alertTitle: "Alert!", alertMessage: "Username or password is empty", actionTitle: nil, onAction: nil, cancelAction: "Dismiss", self)
} else {
if let language = languangeTextfield.text{
LoginViewController.languageChosen = setLanguageChosen(languagetextfield: language)
}

AuthServices().checkUserId(id: usernametext, password: passwordText, onSeccuss: {
self.setLanguage()
self.performSegue(withIdentifier: "showHomePage", sender: nil)
}, onError: { (error) in
AlertMessage().showAlertMessage(alertTitle: "Alert!", alertMessage: error, actionTitle: nil, onAction: nil, cancelAction: "Dismiss", self)
}, activityIndicator: activityIndicator)
}
}

这是 checkUserId 函数

func checkUserId(id: String, password: String, onSeccuss: @escaping () -> Void, onError: @escaping (_ ErrorMessage: String) -> Void, activityIndicator: UIActivityIndicatorView){
arrayOfResult = login.CheckLogin(username: id, password: password, error: "", langid: language, activityIndicator: activityIndicator)

if !arrayOfResult.isEmpty{
if arrayOfResult[0] == "0"{
AuthServices.currentUserId = id
AuthServices.currentUserName = arrayOfResult[1]
onSeccuss()
} else {
if let error = arrayOfResult[0]{
onError(error)
}
}
} else {
print("Oops, something went wrong!")
}
}

这是 urlsession

public func CheckLogin(username:String, password:String, error:String, langid:Int, activityIndicator: UIActivityIndicatorView)-> [String?]{
var soapReqXML:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"

soapReqXML += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
soapReqXML += " xmlns:xsd =\"http://www.w3.org/2001/XMLSchema\""
soapReqXML += " xmlns:soap =\"http://schemas.xmlsoap.org/soap/envelope/\">"
soapReqXML += " <soap:Body>"
soapReqXML += "<CheckLogin xmlns=\"http://tempuri.org/\">"
soapReqXML += "<username>"
soapReqXML += username
soapReqXML += "</username>"
soapReqXML += "<password>"
soapReqXML += password
soapReqXML += "</password>"
soapReqXML += "<error>"
soapReqXML += error
soapReqXML += "</error>"
soapReqXML += "<langid>"
soapReqXML += String(langid)
soapReqXML += "</langid>"
soapReqXML += "</CheckLogin>"
soapReqXML += "</soap:Body>"
soapReqXML += "</soap:Envelope>"

let soapAction :String = "http://tempuri.org/CheckLogin"

let responseData:Data = SoapHttpClient.callWS(Host : self.Host,WebServiceUrl:self.Url,SoapAction:soapAction,SoapMessage:soapReqXML, activityIndicator: activityIndicator)

let strVals :[String?] = stringArrFromXML(data : responseData);
var vals = [String?]()
for i in 0 ..< strVals.count {
let xVal = strVals[i]
vals.append(xVal)
}
let returnValue:[String?] = vals
return returnValue
}


public class func callWS(Host:String,WebServiceUrl:String, SoapAction:String, SoapMessage:String, activityIndicator: UIActivityIndicatorView)-> Data{
activityIndicator.startAnimating()
self.Error = nil;
self.ErrorString = nil;
self.StatusCode = nil;
self.StatusDescription = nil;
self.ResponseData = nil;
self.ResponseString = nil;

var responseData : Data = Data()

let semaphore = DispatchSemaphore.init(value: 0)
let url = URL.init(string: WebServiceUrl)
let req = NSMutableURLRequest(url: url!)

let session = URLSession.shared
req.httpMethod = "POST"
req.httpBody = SoapMessage.data(using: String.Encoding.utf8, allowLossyConversion: false)
req.addValue(Host, forHTTPHeaderField: "Host")
req.addValue("text/xml;charset =utf-8", forHTTPHeaderField: "Content-Type")

let contentLength = SoapMessage.utf8.count
req.addValue(String(contentLength), forHTTPHeaderField: "Content-Length")
req.addValue(SoapAction, forHTTPHeaderField: "SOAPAction")

let task_ = session.dataTask(with: req as URLRequest){ (data, response, error) in
DispatchQueue.main.async {
activityIndicator.stopAnimating()
}
self.Error=error

if let httpResponse = response as? HTTPURLResponse {
self.StatusCode = httpResponse.statusCode
if httpResponse.statusCode != 200 {
self.StatusCode=httpResponse.statusCode
self.ErrorString=httpResponse.description

responseData = Data()
self.ResponseData = Data()
} else {
responseData = data!
self.ResponseData = data
let responseString = String.init(data: data!, encoding: String.Encoding.utf8)
self.ResponseString = responseString!
}
}
semaphore.signal()
}
task_.resume()

semaphore.wait()
return responseData
}

这是 Storyboard的图片

enter image description here

提前谢谢大家

最佳答案

假设您的 UIActivityIndi​​catorView 实际上已添加到您的 View 层次结构中,听起来您的指示器 View 可能不是堆栈中的最前面的 View 。

您需要在 Storyboard 中修复该问题,或者让父 View 使用 UIView 的 bringSubviewToFront(_ view: UIView) 将其向前显示。

关于ios - 如何在调用 SOAP 网络服务时显示事件指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50933118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com