English 中文(简体)
xcode datatask not running
原标题:

I am new in using swift5. I am going to integrate Apple Pay with my app, however the datatask seems not working cannot see any log from the console. Can anyone tell me what I am done wrong? also how can I verify/ debug the request and response to the backend server.

   struct IssuerRequest: Codable{
       let certificates: [Data]
       let nonce: Data
       let nonceSignature: Data
   }


    struct IssuerResponse: Codable {
        let activationData: Data
        let ephemeralPublicKey: Data
        let encryptedPassData: Data
    }



 func execute(request: IssuerRequest, cardNumber: String, onFinish:@escaping (IssuerResponse) -> ()){
        guard let prefix = Bundle.infoPlistValue(forKey:"URL") as? String else { return }
  
    let url = URL(string: prefix + "/get/applepay")!
    var urlRequest = URLRequest(url: url)
    urlRequest.httpMethod = "POST"
    do {
        let jsonData = try JSONEncoder().encode(request)
        urlRequest.httpBody = jsonData
        print("req json data: (jsonData)")
    }catch let jsonError{
        print(jsonError)
    }
    
    var issuerResponse: IssuerResponse!
    let dataTask = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
        if let error = error {
            print("Error: (error)")
            return
        }
        guard let data = data, let response = response as? HTTPURLResponse else{
            print ("Error: No Response Object")
            return
        }
        guard response.statusCode == 200 else {
            print("Error: Server response status (response.statusCode)")
            return
        }
        
        do {
            let issuerResponse = try JSONDecoder().decode(IssuerResponse.self, from: data)
        } catch let jsonError {
            print(jsonError)
        }
        onFinish(issuerResponse)
    }
    dataTask.resume()
}

Hope I can debug the api call

问题回答

暂无回答




相关问题
xcode datatask not running

I am new in using swift5. I am going to integrate Apple Pay with my app, however the datatask seems not working cannot see any log from the console. Can anyone tell me what I am done wrong? also how ...

How to hide NavigationView Bar in SwiftUI

I cannot hide NavigationView bar. I tried both variants: Code 1: public var body: some View { NavigationView { MasterView() .navigationBarHidden(true) } } Code 2: ...

Apple Pay & Google Pay (P2P) with Flutter

I m new to Payment Integration and I want to use Apple Pay and Google Pay as an option in my flutter app. I ve discovered this package Pay that integerates both of them. the case is that I want to let ...

热门标签