alamofire

How to Connect localhost (with invalid certificate) using Alamofire?

大兔子大兔子 提交于 2019-12-18 12:24:25
问题 This my first project using swift. I am usin alamofire to connect the API. I have a local copy form the API I want to use for debugging - so I can set test data - because the remote API has already real data that I can't mess with. The problem is I am getting the below error when I try to access https://localhost:8443/MyProject Optional(Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “localhost”

Cocoapods + Cannot load underlying module for 'x'

被刻印的时光 ゝ 提交于 2019-12-18 11:14:27
问题 I am running XCode 7, Swift 2.0, iOS 9. I want to install Alamofire in my project using Cocoapods. I have done the following: gem install cocoapods pod setup pod init Updated Podfile to: # Uncomment this line to define a global platform for your project # platform :ios, '9.0' use_frameworks! target 'JSONeg' do pod 'Alamofire', :branch => 'swift-2' end Then I installed the pod: pod install And I added the following to ViewController.swift import Alamofire This raises the following error:

Handling XML data with Alamofire in Swift

烂漫一生 提交于 2019-12-18 10:44:29
问题 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,

How can I log each request/response using Alamofire?

谁说我不能喝 提交于 2019-12-18 10:38:09
问题 Is there a way to log each request / response using Alamofire (something similar to AFNetworkActivityLogger) ? I am aware of Printable, DebugPrintable and Output (cURL) but they are not quite what I am looking for. 回答1: Something like this might be what you were looking for: extension Request { public func debugLog() -> Self { #if DEBUG debugPrint(self) #endif return self } } Usage: Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"]) .debugLog() .response {…} If you

Swift 4 - Get an Upload Image Progress using URLSession

我与影子孤独终老i 提交于 2019-12-18 09:54: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<

Swift Function to parse JSON and return a array of dictionaries

风流意气都作罢 提交于 2019-12-18 09:45:58
问题 I tried to write a function to parse a JSON. The return-value of the function is an array of dictionaries. Unfortunately, I have the problem that the assignment result = data as! [[String:AnyObject]] does not work. the print(data) returns my JSON wonderful back but the print(result) only gives me a empty array back. surprising it is that the method print(result) runs first and then the method print(data) run. The code i have try: import Foundation import Alamofire import SwiftyJSON func

Dictionary is not convertible to Void

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:11:49
问题 Hi guys I've been searching the net without much luck but I'm trying to get around Alamofires asynchronous nature. I'm trying to return the JSON response as a dictionary but Xcode is giving me "Dictionary is not convertible to 'Void'" func homePageDetails(userName:String) -> (Dictionary<String,AnyObject>){ let username = userName let hompePageDetails = Alamofire.request(.GET, "http://example.com/API/Bunch/GetHomePageDetails/\(username)/").responseJSON{(request, response, JSON, error) in print

URL Encode Alamofire GET params with SwiftyJSON

对着背影说爱祢 提交于 2019-12-18 05:18:16
问题 I am trying to have Alamofire send the following parameter in a GET request but it's sending gibberish: filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //www.example.com/example?filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //Obviously URL encoded This is my code: let jsonObject = ["$and":[["name":["$bw":string], "country":"gb"]]] let json = JSON(jsonObject) print(json) outputs { "$and" : [ { "name" : { "$bw" : "duke" }, "country" : "gb" } ] } This is my params request:

Is there a way to do Alamofire requests with retries

笑着哭i 提交于 2019-12-18 04:01:50
问题 I have a lot of places in the code where Alamofire request/response are handled. Each of this requests may fail because of some intermittent problem (the most common is flaky network). I would like to be able to retry requests 3 times before bailing out. The straightforward method would be to having something like that var errorCount = 0 func requestType1() { let request = Alamofire.request(...).responseJSON { response in if (isError(response) && errorCount < 3) { errorCount += 1 request1() }

swift JSON login REST with post and get response example

﹥>﹥吖頭↗ 提交于 2019-12-17 22:33:08
问题 It's my first experience with REST in iOS development with swift. I couldn't find any working or straight (simple) example for doing what i need here. I have a login backend (https://myaddress.com/rest/login), where I need to pass 2 params: login and password. When I pass good values (user exists in database) I get 2 variables as a result: token (string) and firstLogin (bool). So when I get those values I know that login is successful and I can log in into my app. So I am begging you for an