简体   繁体   English

从后台提取调用时,Alamofire无法正常工作

[英]Alamofire not working while called from background fetch

I'm using background fetch in an iOS app to schedule some notifications and I need to fetch some data from server But when i create an Alamofire request the surver returns the data but alamofire does not calles my compilation handler (responseString) 我在iOS应用中使用后台获取来安排一些通知,并且需要从服务器获取一些数据,但是当我创建Alamofire请求时,surver返回数据,但是alamofire不会调用我的编译处理程序(responseString)

the exact same code works perfectly while my app is on forground. 当我的应用程序在地面上时,完全相同的代码可以完美地工作。

Alamofire.request(url, method: method ?? HTTPMethod.get, parameters: parameters,
        encoding: encoding ?? URLEncoding.default, headers: headers)
        .responseString{
        (afResponse : DataResponse<String>) -> Void in
    ....
}

I used AlamofireNetworkActivityLogger to check weather the response is created and fetched and the result was true. 我使用AlamofireNetworkActivityLogger来检查创建和获取响应的天气,结果为true。 but my compilation handler not getting called! 但是我的编译处理程序没有被调用!

any thing else should I consider while using Alamofire in background? 在后台使用Alamofire时我还应该考虑其他事项吗?

Have you tested if it is working as suggested in Alamofire network calls not being run in background thread 您是否测试了它是否按Alamofire网络调用中的建议在后台线程中未运行

We may have to start the call from background thread instead of the main thread (as it is the default behaviour). 我们可能必须从后台线程而不是主线程开始调用(因为这是默认行为)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM