Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

swiftui - Untap button after sending a POST request

I'm currently working with POST requests and I'm trying to POST data to postman. The data is being sent, but after I press the "send" button, it won't untap. What could be the reason behind it? This is my button view:

        Button(action: {
                loginManager.firstName = addFirstName
                loginManager.lastName = addLastName
                loginManager.emailAddress = addEmail
                loginManager.phoneNumber = addPhoneNumber
                loginManager.addNewUser()
        }) {
            ZStack {
            Text("Send")
            }
        }

And this is the section of the addNewUser function that sends the data to postman:

let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
            
            // Check for Error
            if let error = error {
                print("Error took place (error)")
                return
            }
     
            // Convert HTTP Response Data to a String
            if let data = data, let dataString = String(data: data, encoding: .utf8) {
                print("Response data string:
 (dataString)")
            }
    }
    task.resume()
    semaphore.wait()

Is there something that I'm missing? Thanks in advance!

question from:https://stackoverflow.com/questions/65874554/untap-button-after-sending-a-post-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...