alamofire

Alamofire with a self-signed certificate / ServerTrustPolicy

不打扰是莪最后的温柔 提交于 2019-11-27 13:34:34
I want to use Alamofire to communicate with my server over a https connection with a self signed certificate. My environment runs on localhost. I've tried to connect, but the response all the time looks like this: Success: false Response String: nil I've done it with the following code: import Foundation import UIKit import Alamofire class MessageView: UITableViewController { let defaultManager: Alamofire.Manager = { let serverTrustPolicies: [String: ServerTrustPolicy] = [ "localhost": .DisableEvaluation ] let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()

Alamofire 4.0 Upload MultipartFormData Header

给你一囗甜甜゛ 提交于 2019-11-27 13:09:10
问题 How do we add an authentication header to the upload function of Alamofire 4.0? below is the sample code, however I see no way in adding a header to the function. Alamofire.upload( multipartFormData: { multipartFormData in multipartFormData.append(unicornImageURL, withName: "unicorn") multipartFormData.append(rainbowImageURL, withName: "rainbow") }, to: "https://httpbin.org/post", encodingCompletion: { encodingResult in switch encodingResult { case .success(let upload, _, _): upload

那些在学习iOS开发前就应该知道的事(part 2)

◇◆丶佛笑我妖孽 提交于 2019-11-27 12:04:41
英文原文: Things I wish I had known before starting iOS development—Part 2 如果你还没读这篇文章的第一部分,请先读完了再来看第二部分。 那些在学习iOS开发前就应该知道的事(part 1) : 设计师设计出来了一个不错的引导界面,然而当我看到设计稿的时候,我们的app也没几天就要上线了…… 在第一部分中,我讨论了学习iOS开发的一些基本问题。第二部分将更多地讨论一些实际问题,这些问题都是你在开发iOS应用时会遇到的。 Debugging 毋庸置疑,你在开发应用的过程中一定会遇到很多错误和异常。比如,你会遇到NSInvalidArgumentException,遇到NSInternalInconsistencyException,还会遇到“0xfaded322”这种错误代码。有时候你可以在Stack Overflow或Quora上找到答案,但大部分时候你得自力更生。 Xcode具有断点、视图调试和日志的功能,是debug的不二之选。但毕竟孤掌难鸣,你仍需为它找些得力的帮手。 1.Pony Debugger square/PonyDebugger : PonyDebugger - 使用Chrome Developer Tools,为你的native iOS应用进行远程网络和数据调试。 square开发了这个强大的开源工具

Any way to get the response body during HTTP errors?

坚强是说给别人听的谎言 提交于 2019-11-27 11:56:26
问题 I'm hitting an API that will occasionally throw a HTTP 403 error, and the response body can give some extra information in the form of json, however for the life of me I can't seem to get the information back out from the Alamofire response objects. I see the information in developer tools if I hit the API via chrome. Here's my code: Alamofire.request(mutableURLRequest).validate().responseJSON() { (response) in switch response.result { case .Success(let data): if let jsonResult = data as?

How to migrate Alamofire router class to Swift 3?

女生的网名这么多〃 提交于 2019-11-27 11:45:20
问题 Does anybody know how to change this entire approach to Swift 3? At this moment I have something very similar to this working OK on Swift 2.2 but now I'm trying to change that to Swift 3. I am getting some errors with the "URLRequestConvertible", with the Alamofire.Method (that I changed to HTTPMethod and now is working) and also with the parameter encoding, besides that I'm not conforming the entire protocol. I'm waiting for guidance from engineers at Alamofire, but I am looking to see what

How to load image in swift using Alamofire

末鹿安然 提交于 2019-11-27 11:45:14
问题 I have a collection view controller, which load image Async by URL. (Something like Instegram) I am looking for the best way to implement the part of the loading image. please tell me what do you think First way - without any external library: let downloadQueue = dispatch_queue_create("com.pro.asyncImages",nil) dispatch_async(downloadQueue){ var data = NSData(contentsOfURL: NSURL(string: pictureUrl!)!) var image: UIImage? if (data != nil){ image = UIImage(data: data!) } dispatch_async

AlamoFire Download in Background Session

这一生的挚爱 提交于 2019-11-27 11:13:22
I am using Alamofire within a new app (A Download Manager Sample based on Alamofire) I need some clarifications about downloading files using the background session. I need to override SessionDelegate to get it works? Or just backgroundCompletionHandler ? Typically what are the steps to handle downloads in background using Alamofire? And how can I handle the case where my app is relauch, with downloads in flux. József Vesza Update Based on this amazing tutorial , I have put together an example project available on GitHub . It has an example for background session management. According to Apple

Swift 3 Alamofire multipart upload

本小妞迷上赌 提交于 2019-11-27 11:04:49
问题 Thanks to migration to Swift 3, I find it difficult to compile my project that uses Alamofire. The problem occurs when uploading multipartFormData: Alamofire.upload(.POST, URL, headers: headers, multipartFormData: { multipartFormData in . . . }) Ambiguous reference to member 'upload(_:to:method:headers:)' Any help much appreciated, thanks in advance! RESOLVED: Alamofire.upload(multipartFormData: { (multipartFormData) in multipartFormData.append(fileData, withName: "file_pack", fileName: "file

Swift Alamofire: How to get the HTTP response status code

本秂侑毒 提交于 2019-11-27 10:30:58
I would like to retrieve the HTTP response status code (e.g. 400, 401, 403, 503, etc) for request failures (and ideally for successes too). In this code, I am performing user authentication with HTTP Basic and want to be able to message the user that authentication failed when the user mistypes their password. Alamofire.request(.GET, "https://host.com/a/path").authenticate(user: "user", password: "typo") .responseString { (req, res, data, error) in if error != nil { println("STRING Error:: error:\(error)") println(" req:\(req)") println(" res:\(res)") println(" data:\(data)") return } println(

Pagination with UICollectionView working with API

﹥>﹥吖頭↗ 提交于 2019-11-27 08:52:49
问题 I have a working application where I am using Alamofire and SwiftyJSON to fetch images from flicr API. Now, I want to include pagination in the returned images. I am returning 5 images when the application launches and this number can increase. I want to achieve this with the UICollectionView . My codes are written below. Any help would be appreciated. 100 items are being returned on every page. Services func setData(json: JSON) -> Void { if let photos = json["photos"]["photo"].array { for