
Запрос Аламофайра
class APIService
{
let eventAPIKey: String
let eventBaseURL: URL?
static let kEventID = "id"
init(APIKey: String)
{
self.eventAPIKey = APIKey
eventBaseURL = URL(string: BASE_URL)
}
func validatePasscode(eventCode: String, completion: @escaping (Event?) -> Void)
{
if let passcodeURL = URL (string: PASSCODE_CHECKER_URL) {
Alamofire.request(passcodeURL, method: .post).validate().responseJSON { (response) in
switch response.result{
case .success:
if let eventJSON = response.result.value{
let eventObject:Dictionary = eventJSON as! Dictionary
let eventidObject: Dictionary = eventObject[APIService.kEventID] as! Dictionary
let event:String = eventidObject[APIService.kEventID] as! String
print(event)
}
case .failure(let error):
print("\(error)")
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/519 ... e-code-404
Мобильная версия