alamofire

Twitter Application-only authentication always return 401

十年热恋 提交于 2019-12-11 04:05:42
问题 I am trying to authenticate using App only auth and I successfully get the bearer token but when I try to make calls to the REST APIs, I always get an 401 error, here is my code: private var accessToken: String? private let consumerKey = "*********" private let consumerSecret = "*********" private let baseUrlString = "https://api.twitter.com/1.1/" private let pageSize = 20 private func authenticate(completionBlock: Void -> ()) { if accessToken != nil { completionBlock() } let credentials = "\

simple way to map a json collection response into swift object class

走远了吗. 提交于 2019-12-11 03:54:50
问题 Ive tried a lot of libraries, Alamofire, JsonHelper, ObjectMapper etc..., but unfortunately, Ive coundn't map a json collection response into an object class. Im developing an IOS 8 App with swift 1.2 and xcode 6.3, and two classes of my model are: Club.swift class Club { var id: String = "" var name: String = "" var imageUrl: String = "" var hasVip: Bool = false var desc: String = "" var location: [Location] = [] } Location.swift class Location { var country: String = "" var city: String = "

How to make a NTML request with Alamofire 4.0?

好久不见. 提交于 2019-12-11 02:58:25
问题 These are request headers: let headers: HTTPHeaders = [ "Accept": "application/json", "username": "someUserName", "password": "aPasswordForSomeUserName" ] When making a request with below code it's giving me "Garbage at the end". However, when I checked the response with JSON parser online. It's a valid JSON. Alamofire.request("http://myserver/list.svc/random", headers: headers).responseJSON { response in print(response) } I also tried making a request like this : Alamofire.request("http:/

Do I need DispatchQueue.main to update UI after an Alamofire request?

风流意气都作罢 提交于 2019-12-11 02:41:37
问题 I'm following a tutorial about working with REST/web requests . In the tutorial, we're working towards a Pokedex app where we fetch Pokemon details from an API using Alamofire , and then displaying that data in our UIs. Here's the related code: typealias DownloadComplete = (Bool) -> () // Model class func downloadPokemonDetails(completed: @escaping DownloadComplete) { Alamofire.request(_pokemonURL).responseJSON { (response) in var success = true if let jsonData = response.result.value as?

Swift 3 Alamofire 4 Upload array of images with parameters

佐手、 提交于 2019-12-11 02:37:19
问题 I'm trying to upload an array of pictures along with some parameters using Alamofire 4 and Swift 3. The parameters seem to work because the update is done, but the images don't get to the server In Postman I can do this fine with no problem: Postman request sample This is my code so far: let parameters = [ "service_request_id" : servicesID, "status_id" : "4", ] Alamofire.upload( multipartFormData: { multipartFormData in for (key,value) in parameters { if let value = value as? String {

Alamofire upload image with multipart/form-data

天涯浪子 提交于 2019-12-11 02:24:17
问题 i am looking for a working sample code to upload an image with multipart/form-data using Alamofire i can't get this code to work with my project Alamofire.upload( .POST, URLString: "http://httpbin.org/post", multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(fileURL: unicornImageURL, name: "unicorn") multipartFormData.appendBodyPart(fileURL: rainbowImageURL, name: "rainbow") }, encodingCompletion: { encodingResult in switch encodingResult { case .Success(let upload, _,

tableView.reloadData() error: Ambiguous reference to member

旧街凉风 提交于 2019-12-11 02:08:54
问题 I'm trying to reload the data in my table once a successful GET request has been performed. However I was thrown this error when I wrote self.tableView.reloadData() : Ambiguous reference to member 'tableView(_:numberOfRowsInSection:)' This is the affected code override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() let url = "http://api.myawesomeapp.com" Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { case .Success(let data): let

Alamofire progress returns -1 even though Content-Length is set

家住魔仙堡 提交于 2019-12-11 01:28:40
问题 When I print out the expected bytes from an Alamofire progress call it always prints -1 until the very end, when it prints the total. However, if I run a curl command against the webserver I get header output which very clearly lists the Content-Length header. Why is it always saying -1? 回答1: Try this, Pass Accept-Encoding key in header. It worked for me. let headers = ["Accept-Encoding" : ""] Alamofire.download(.POST, urlString, headers: headers, destination: destination) .progress {

How to handle the response of all types of requests in one handler, but also uniquely handle every request with Alamofire and Moya

限于喜欢 提交于 2019-12-11 01:08:54
问题 In my app I use Moya and Alamofire (And also Moya/RxSwift and Moya-ObjectMapper) libraries for all network requests and responses. I would like to handle the response of all types of requests in one handler, but also uniquely handle every request. For example for any request I can get the response "Not valid Version", I would like to avoid to check in every response if this error arrived. Is there an elegant way to handle this use case with Moya ? 回答1: Apparently that is very simple, You just

how to upload an Image using alamofire with basic authentication?

ぐ巨炮叔叔 提交于 2019-12-11 00:54:09
问题 I am trying to upload an image using alamofire 4.7.1 with this code, but to be honest I suspect that I didn't write a right code to upload the image func uploadDefect(defectRemark: String, defectLocation: String, defectImage: UIImage, fileNameImage: String, completion: @escaping(_ errorMessage: String?) -> Void) { guard let imgData = defectImage.jpeg(.medium) else {return} let urlUpload = URLService.uploadDefect.endPoint let username = "admin" let password = "1234" let credentialData = "\