alamofire

Alamofire request gets stuck when entering background?

橙三吉。 提交于 2021-02-18 22:37:12
问题 I'm using Alamofire to make a call to a webservice which takes a pretty long time to load. If the app goes into the background I get stuck with my loader when I return to the app. I imagine it's because the call never returns anything to my completion handler. How can I address this problem? 回答1: You can use background fetching to solve this problem. It can be done in the following way in Swift 3: var backgroundTask: UIBackgroundTaskIdentifier? // global variable backgroundTask =

saving swifty json array to user defaults

 ̄綄美尐妖づ 提交于 2021-02-16 16:36:23
问题 i have a json data which gives the following information: let data = [ { "QuestionTitle" : "Entomology is the science that studies", "Id" : 205, "Options" : [ { "Option" : "Insects", "Id" : 810 }, { "Option" : "The origin and history of technical and scientific terms", "Id" : 811 }, { "Option" : "The formation of rocks", "Id" : 812 }, { "Option" : "Behavior of human beings", "Id" : 809 } ] }, { "QuestionTitle" : "A train running at the speed of 60 km\/hr crosses a pole in 9 seconds. What is

Completion gets called soon

ぐ巨炮叔叔 提交于 2021-02-15 07:43:45
问题 I have the following functions. I'm trying to pass allItems array into the completion block of requestItems , but I get a crash as it says it's nil. I removed the completion to check that item has a value and it does. That means that the completion executes before the for loop. Is there another approach for this? Something like Promises in Javascript that will execute the completion when the for loop has finished. func requestItems(_ data: [String: Any], completion: (Bool, [Item]) -> Void) {

Alamofire empty array

一世执手 提交于 2021-02-11 14:52:30
问题 I'm novice programmer and I've been working on movie app and couldn't figure out why Alamofire returns my single parameters from JSON response but doesn't do it in for loop. Here is the code. This function is inside class. class oneMovie: ObservableObject{ @Published var Movie = Movies() private let API : String var url : String init(ID: String){ self.API = "API" self.url = "url.to.somewhere\(ID)" MovieGetter(URL: url) } func MovieGetter(URL: String){ AF.request(URL).responseJSON { (response)

URLSession dataTask method returns 0 bytes of data

时光毁灭记忆、已成空白 提交于 2021-02-10 16:14:07
问题 I am using URLSession's dataTask method with a completion handler. The error in response is nil, but the data object returns something, it returns 0 bytes of data. I was using Alamofire library firstly, I thought there is something wrong with it because I started using newer version so I stated using my own implementation of Alamofire just so I don't have to rewrite all the calls I already have in my app. It still returns 0 bytes of data. When I use the same URL in the Playground with a

URLSession dataTask method returns 0 bytes of data

限于喜欢 提交于 2021-02-10 16:08:24
问题 I am using URLSession's dataTask method with a completion handler. The error in response is nil, but the data object returns something, it returns 0 bytes of data. I was using Alamofire library firstly, I thought there is something wrong with it because I started using newer version so I stated using my own implementation of Alamofire just so I don't have to rewrite all the calls I already have in my app. It still returns 0 bytes of data. When I use the same URL in the Playground with a

swift Unescaped control character

拜拜、爱过 提交于 2021-02-10 05:56:24
问题 I'm trying to get a json from a server and deserialize it, but I try probelas with unescaped control characters. My code is as follows ... let urlFinal = "http://000.0000.000.000:8080" let jsonUrl = urlFinal let session = NSURLSession.sharedSession() let shotsUrl = NSURL(string: jsonUrl) let task = session.dataTaskWithURL(shotsUrl!) {data, response, error in guard data != nil else { falha() return } //let json = JSON(data: data!) //print(json["ServicoCliente"][0]["id"]) do { let jsonData =

Lipo: input file must be a fat file

社会主义新天地 提交于 2021-02-09 12:11:04
问题 I'm getting following error: Extracting arm64 from Alamofire fatal error: lipo: input file (../myApp.app/Frameworks/Alamofire.framework/Alamofire) must be a fat file when the -extract option is specified always when I want to run the app. It doesn't show up when I clean before, but it takes super long time. This => Lipo Error!! can't open input file is not my case and it doesn't work for me. Any ideas, Thank you 回答1: In target -> Build Phases -> Run script I had some incompatible script. I

Lipo: input file must be a fat file

旧街凉风 提交于 2021-02-09 12:11:01
问题 I'm getting following error: Extracting arm64 from Alamofire fatal error: lipo: input file (../myApp.app/Frameworks/Alamofire.framework/Alamofire) must be a fat file when the -extract option is specified always when I want to run the app. It doesn't show up when I clean before, but it takes super long time. This => Lipo Error!! can't open input file is not my case and it doesn't work for me. Any ideas, Thank you 回答1: In target -> Build Phases -> Run script I had some incompatible script. I

Lipo: input file must be a fat file

╄→гoц情女王★ 提交于 2021-02-09 12:10:49
问题 I'm getting following error: Extracting arm64 from Alamofire fatal error: lipo: input file (../myApp.app/Frameworks/Alamofire.framework/Alamofire) must be a fat file when the -extract option is specified always when I want to run the app. It doesn't show up when I clean before, but it takes super long time. This => Lipo Error!! can't open input file is not my case and it doesn't work for me. Any ideas, Thank you 回答1: In target -> Build Phases -> Run script I had some incompatible script. I