alamofire

Could not cast value of type 'NSMutableURLRequest' (0x11beb7040) to 'Alamofire.URLRequestConvertible' (0x11beb9040)

让人想犯罪 __ 提交于 2019-11-29 22:38:33
问题 when build my code then crash on Alamofire.request(request as! URLRequestConvertible).responseJSON() . pls suggest how to fix this crash let url = NSURL(string: "https://jsonplaceholder.typicode.com/users") let request = NSMutableURLRequest(url:url! as URL) request.httpMethod = "GET" request.setValue("application/json", forHTTPHeaderField: "Content-Type") Alamofire.request(request as! URLRequestConvertible).responseJSON(){ response in switch response.result { case .success(let data): print("

Handling XML data with Alamofire in Swift

只谈情不闲聊 提交于 2019-11-29 22:25:47
I started to use cocoapods with my current ios project. I need to use SOAP to get content with easy way for my ios project. I have googled it and Alamofire pod is great for me. Because I am using Swift programming language. I have inited easily this pod. But my web services return me XML result. And I want to serialisation to array this XML result. But I can't. When I call my web service with a browser I get this kind of result Alamofire response method is like this: Alamofire.request(.GET, "http://my-web-service-domain.com", parameters: nil) .response { (request, response, data, error) in

Cancel a request Alamofire

倖福魔咒の 提交于 2019-11-29 22:18:46
I am sending a request which is triggered based on timer. But if I press the back button the request still seems to be active and the response in turns crashes the app. Kindly suggest a way to cancel the request. Using Xcode 8.2.1 Swift 3 Here is the sample request : Alamofire.request(path!, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: createHeader()).responseJSON { response in switch response.result { case .success(let data): success(data as AnyObject?) case .failure(let error) : failure(error as NSError) } } Even tried invalidating the timer on

Could not get the server error message from Alamofire 3.3.0

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 21:39:58
问题 It is my first time for me to use Alamofire , and it got me really frustrated. I'm using the following code to call a signup API on the backend API Alamofire.request(.POST, "\(self.authBaseURL)/signup", parameters: params, headers: headers, encoding: .JSON) .validate(statusCode: 200..<300) .validate(contentType: ["application/json"]) .responseJSON { response in switch response.result { case .Success(let JSON): print("Success with JSON: \(JSON)") success(updatedUser) case .Failure(let error):

Updating to latest version of CocoaPods?

ぐ巨炮叔叔 提交于 2019-11-29 18:45:25
I'm having some issues installing Alamofire 4.0 into my project. I've got the latest version of Xcode , running Swift 3 , and when I try to install alamofire I'm getting like 800 compiler errors. Apparently CocoaPods 1.1.0+ is required to build Alamofire 4.0.0+ I looked at the version of CocoaPods I have in terminal and it says I'm at 1.0.1. Running an update didn't work I guess because CocoaPods 1.1 is in beta. So I'm not exactly sure how to update it up to where I'm good to go. Unless being out of date doesn't force like 800 compiler errors? Does that sound like some other issue? user3899562

Swift 2.0, Alamofire: Set cookies in HTTP Post Request

不羁的心 提交于 2019-11-29 18:24:37
问题 I want to set cookies in my HTTP POST request. Something like the cookie field in the HTTP Request below, version: 0.1.7 Cookie: client=Android; version=0.1.7; sellerId=SEL5483318784; key=178a0506-0639-4659-9495-67e5dffa42de Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Content-Length: 1431 How can I achieve this with Alamofire? My current Alamofire request is like this, Alamofire.request(.POST, ServerConfig.ADD_PRODUCT_URL, parameters: productJSON, encoding: .JSON, headers:

Swift 4 - Get an Upload Image Progress using URLSession

我们两清 提交于 2019-11-29 18:03:25
I have this kind of code below func upload(){ let img = UIImage(named: "1") let imgData = UIImageJPEGRepresentation(img!, 1) let data = imgData?.base64EncodedString() var request = URLRequest(url: URL(string: url)!) request.httpMethod = "POST" request.setValue("\(auth)", forHTTPHeaderField: "Authorization") request.setValue("application/xml", forHTTPHeaderField: "Content-Type") var postString = "<uploadrequest>" postString += "<folderid>123</folderid>" postString += "<folder_name>images</folder_name>" postString += "<image_byte>\(data!)</image_byte>" postString += "</uploadrequest>" request

Why can't I get the request result form Alamofire

淺唱寂寞╮ 提交于 2019-11-29 17:38:58
I can't get the result of Alamofire request.So,I created ouput of an array that I got from json async call.I can't get the resultArray out of dispatch {...}.When I add println to debug the code.The second one appear first before the first one. All i want to resultArray to get the data from Alamofire to display in UIPickerView.Please Help!!! Here is my code import UIKit import Alamofire class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{ @IBOutlet var venuePicker : UIPickerView? var resultOld = [String:String]() // i need it to get only value from json var

Swift - How to save memory using AlamofireImage/ImageShack?

人走茶凉 提交于 2019-11-29 17:31:32
I'm using Alamofire , AlamofireImage to cache images using ImageShack storage with Firebase backend. Sometimes memory comes over 100MB. I want to learn how to improve my image caching and well scaling before uploading. For example I have declared one common cache in class whole project using that AutoPurgingImageCache : let photoCache = AutoPurgingImageCache( memoryCapacity: 100 * 1024 * 1024, preferredMemoryUsageAfterPurge: 60 * 1024 * 1024 ) Is there any way to define these memoryCapacity , preferredMemoryUsageAfterPurge to save memory? What do they mean exactly? I'm using below Alamofire

Capturing data from Alamofire

北城余情 提交于 2019-11-29 16:54:13
I'm having trouble retrieving data from my Alamofire request asynchronously. class BookGetter { static let instance = BookGetter() func getBook(bookId: String) -> Book { let rootUrl = "https://www.someusefulbookapi.com/bookid=?" let url = rootUrl + bookId var title = "" Alamofire.request(.GET, url).response { response in let jsonDict = JSON(data: response.2!) title = String(jsonDict["items"][0]["volumeInfo"]["title"]) } let book = Book(title: title) print(book.title) return book } } The output of print(book.title) is "" , and I understand this is because the print statement is running before