Skip to content

Swift

Getting started with SWIFT

To use the API with SWIFT use the following example

Using URLSession

    import Foundation
    #if canImport(FoundationNetworking)
    import FoundationNetworking
    #endif

    var semaphore = DispatchSemaphore (value: 0)

    let parameters = "{\"api_key\":\"777XXXXXXXXXXXXXXXXXXXAWVwNpSM=\",\"pc\":\"HOME006\"}"
    let postData = parameters.data(using: .utf8)

    var request = URLRequest(url: URL(string: "https://apiv1.pataa.com/get-pataa")!,timeoutInterval: Double.infinity)
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")

    request.httpMethod = "POST"
    request.httpBody = postData

    let task = URLSession.shared.dataTask(with: request) { data, response, error in 
    guard let data = data else {
        print(String(describing: error))
        semaphore.signal()
        return
    }
    print(String(data: data, encoding: .utf8)!)
    semaphore.signal()
    }

    task.resume()
    semaphore.wait()