alamofire

How to run synchronically two functions with async operations on iOS using Swift

两盒软妹~` 提交于 2019-12-03 06:22:34
问题 lets propose this scenario a method with async network operations func asyncMethodA() -> String? { result : String? Alamofire.manager.request(.POST, "https://www.apiweb.com/apimethod", parameters: parameters, encoding:.JSON) .response { (request, response, rawdata, error) in if (response?.statusCode == 200) { //DO SOME HEAVY LIFTING } } return result //string } another method with async network operations func asyncMethodB() -> String? { result : String? Alamofire.manager.request(.POST,

Swift “retry” logic on request

断了今生、忘了曾经 提交于 2019-12-03 06:04:38
问题 So i'm a bit lost on how to implement a retry logic when my upload request fail. Here is my code i would like some guidance on how to do it func startUploading(failure failure: (NSError) -> Void, success: () -> Void, progress: (Double) -> Void) { DDLogDebug("JogUploader: Creating jog: \(self.jog)") API.sharedInstance.createJog(self.jog, failure: { error in failure(error) }, success: {_ in success() }) } 回答1: Here's a general solution that can be applied to any async function that has no

How to use a Proxy Server with Alamofire 4 and Swift 3

吃可爱长大的小学妹 提交于 2019-12-03 05:29:40
Please don't mark as duplicate, I haven't been able to solve my Issue with the existing threads. I'm trying to use my Proxy for an API request that needs a specified IP. To debug my issue, I'm requesting the IP from a webservice. This is my current code: import UIKit import Alamofire class ViewController: UIViewController { var requestManager = Alamofire.SessionManager.default override func viewDidLoad() { super.viewDidLoad() } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(true) var proxyConfiguration = [NSObject: AnyObject]() proxyConfiguration[kCFNetworkProxiesHTTPProxy

AlamoFire does not respect timeout interval

自古美人都是妖i 提交于 2019-12-03 05:28:23
问题 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,

Proper model for multiple Alamofire requests for multiple websites

♀尐吖头ヾ 提交于 2019-12-03 05:11:52
I am using Alamofire to scrap web pages for some data, let’s say News. News is a generic object with something like title, content, picture, date, author etc. However for each web site, I use different method. For some I use json for others I use hpple to extract the data. How can I create a some kind of service for each website. Should I create different Services for each web site or is there a better way to use some kind of generic function templates for each web site. Like Login() Fetch() Populate() return News(…..) Then after I create the news and populate the tableview, how can I refresh

Alamofire Post Request Issues

*爱你&永不变心* 提交于 2019-12-03 04:00:01
let parameters = [ "checkout": [ "email": "john.smith@example.com", "line_items": [ "variant_id": 31342168513, "quantity": 1 ], "shipping_address": [ "first_name": "John", "last_name": "Smith", "address1": "126 York St.", "city": "Ottawa", "province_code": "ON", "country_code": "CA", "phone": "(123)456-7890", "zip": "K1N 5T5" ] ] ] let urlString = "https://\(Key):\(Password)@sapphireonline-staging.myshopify.com/admin/checkouts.json" let headers: HTTPHeaders = [ "X-Shopify-Storefront-Access-Token": "5681ded39ead3fa6f4594ad0981367", "Content-Type": "application/json" ] Alamofire.request

Alamofire invalid value around character 0

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Alamofire . request (. GET , "url" ). authenticate ( user : "" , password : "" ). responseJSON () { ( request , response , json , error ) in println ( error ) println ( json ) } This is my request with Alamofire, for a certain request it sometime works, but sometimes i get: Optional ( Error Domain = NSCocoaErrorDomain Code = 3840 "The operation couldn’t be completed. (Cocoa error 3840.)" ( Invalid value around character 0. ) UserInfo = 0x78e74b80 { NSDebugDescription = Invalid value around character 0. }) Why am i getting this

Command /bin/sh failed with exit code 1 and Embedded pods framework

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Not able to identified actual issue, During updating coco pod getting a message " Re-creating CocoaPods due to major version update. " (that was come only once) and pod updation is successful. After on build i am getting the error. Command /bin/sh failed with exit code 1 . Below is some detail also which i am getting Code Signing /Users/Gaurav/Library/Developer/Xcode/DerivedData/Appname-******/Build/Products/Debug-iphoneos/Appname.app/Frameworks/Alamofire.framework with Identity iPhone Developer: Account Name (Account Id) /usr/bin/codesign -

Alamofire request with cookies

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm beginner and I can't figure out how to make a .GET request (however it requires autenthication) with Alamofire. I managed to do this with other web service (login) because it takes parameters argument: parameters = [ "username" : username "password" : password ] Then: Alamofire.request(.POST, loginUrl, parameters: parameters).responseJSON { (request, response, data, error) -> Void in //handling the response } In response header I get some information: [Transfer-Encoding: Identity, Server: nginx/1.4.1, Content-Type: application/json, P3P:

Alamofire can't access keys of json response

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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: Type 'Any' has no subscript members I don't know