alamofire

Swift: download image from Internet and cache them doesn't work properly. need suggestions

大憨熊 提交于 2019-12-02 19:08:27
问题 I am new to swift, and I am building an App that download images from the Internet and display in a UICollectionView, I can achieve this function successfully, however, it seems like overtime you scroll the screen, it downloaded the images again and again, which may causes a lot of data of the users. I found that I can use cache to solve this problem, but it didn't work, I think I did everything right, but seems the data didn't stored in the cache. here is the code, anyone can help me solve

AlamoFire does not respect timeout interval

落爺英雄遲暮 提交于 2019-12-02 18:46:05
class APIClient { var user = User() let alamoFireManager : Alamofire.Manager? let center = NSNotificationCenter.defaultCenter() init(){ let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForRequest = 4 // seconds configuration.timeoutIntervalForResource = 4 self.alamoFireManager = Alamofire.Manager(configuration: configuration) } func test(){ //This does not respect the 4 second time out. Why? self.alamoFireManager!.request(.POST, CONSTANTS.APIEndpoint+"/test", parameters: parameters).responseJSON { (req, res, json, error) in if let json =

Alamofire can't access keys of json response

南笙酒味 提交于 2019-12-02 18:34:36
问题 I'm new to using Alamofire and have encountered an issue. I'm able to run the following code to print out all the data from an API endpoint. Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in if let JSON = response.result.value { print(JSON) } } The issue is that when I run this: Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in if let JSON = response.result.value { print(JSON["firstkey"]) } } I get the error:

How is it possible to perform multiple Alamofire requests that are finished one after another?

故事扮演 提交于 2019-12-02 17:33:35
问题 I would like to perform multiple Alamofire requests. However, because of data dependency a new request should only start when the previous is finished. I already asked a question with a more general example of an asynchronous request which was solved with OperationQueue . However, I do not succeed to achieve the same with Alamofire. public func performAlamofireRequest(_ number: Int, success: @escaping (Int) -> Void)->Void { Alamofire.request(String(format: "http://jsonplaceholder.typicode.com

Does Alamofire store the cookies automatically?

China☆狼群 提交于 2019-12-02 17:31:34
I'm new to Alamofire so I'm sorry if this it's a noob question: this framework stores the cookies automatically ? This is because I have a simple request like this: Alamofire.request(.POST, loginURL, parameters: ["fb_id": fbId, "fb_access_token": fbToken]) .responseJSON { response in //print(response.request) // original URL request //print(response.response) // URL response //print(response.data) // server data //print(response.result) // result of response serialization if let JSON = response.result.value { print("loginURL - JSON: \(JSON)") } } this request response with a cookie session

使用Carthage集成Alamofire

馋奶兔 提交于 2019-12-02 16:12:14
Carthage相较于Cocoapods有着使用灵活,对目标工程改动小的优势,使得它越来越受欢迎。今天就对我使用Carthage集成FBSDK做一个记录。 1、首先 https://github.com/Carthage/Carthage 查看官方网站,安装好Carthage. 在mac上我习惯用homebrew来安装,使用如下两个指令来安装。 安装:brew update brew install Carthage 如果你之前安装过Carthage,那么可以使用如下指令来查看当前版本号以及更新Carthage。 查看:carthage version 升级:brew upgrade carthage 2、安装完成后,cd 到你的工程根目录 Carthage和Cocoapods一样,通过一个文件来管理第三方库。名叫Cartfile 新建Cartfie文件:touch Cartfile 使用Xcode打开进行编辑:open -a Xcode Cartfile Cartfile指定依赖源以及版本号,版本号的控制与Cocoapods一样。 不指定版本号即默认最新版本。 Cartfile文件中的内容示例如下: /*--> */ /*--> */ github "Alamofire/Alamofire" ~>4.5.0 github "Alamofire/AlamofireImage"

having difficulty fetching JSON Dictionary

大城市里の小女人 提交于 2019-12-02 15:56:13
问题 My response from API is items are.....****************** ("user_img", http://www.xxx/Content/Images/Products/NoImageAvailable.jpg) items are.....****************** ("user_posts", 10) items are.....****************** ("5", { "post_id" : 135, "post_img" : [ { "guid" : "http:\/\/www.xxx\/wp- content\/uploads\/2016\/10\/IMG_1477393867.jpg" } ] }) items are.....****************** ("9", { "post_id" : 143, "post_img" : [ { "guid" : "http:\/\/www.xxx\/wp-content\/uploads\/2016\/10\/IMG_1477453054.jpg

Completion handler for Alamofire network fetch

旧街凉风 提交于 2019-12-02 15:49:33
问题 I am attempting to create a function which will return a list of custom objects, created from parsing JSON. I am using AlamoFire to download the content. I have written this function which, on success, creates an array of locations to be returned. However, the returns are always nil. My code is below: func fetchLocations() -> [Location]? { var locations : [Location]? Alamofire.request(.GET, myURL) .responseJSON { response in switch response.result { case .Success(let data): locations =

SSL_ERROR_SSL(1): operation failed within the library

旧街凉风 提交于 2019-12-02 15:45:38
I am getting some SSL Error s (which are causing my project to stop/hang with no crash as I have a DispatchGroup waiting for the request), which I don't know how they are caused, what they are, or what to do about it. I have read numerous pages roughly about this problem, but there are not much documentation or people having the same problem. I have tried changing the info.plist but that doesn't seem to have helped. Both plist 's look like this: ( accounts.spotify.com is the domain for the URL of the access token request) I can see that my code is failing when I make a request to the server.

A solution to track a batch of HTTP requests in swift 3.0

拈花ヽ惹草 提交于 2019-12-02 12:50:00
I am using swift 3.0 running under iOS 10.0 and I want to craft some code that fires when a batch condition is met. for i in 0 ..< rex { async code, disappears and does it stuff } Imagine the async code is a collection of URL requests, that basically background as soon as I loop thru them. Now how can I fire off more code when "rex" requests have completed? I thought of setting up a timer to watch and check every second, but its surely not a good solution. I thought kicking off another thread to simply watch the data being collected, and fire when its quota is full, but well that's worse then