【问题标题】:Alamofire not working while called from background fetch从后台获取调用时,Alamofire 不工作
【发布时间】:2018-05-29 08:44:24
【问题描述】:

我在 iOS 应用程序中使用后台获取来安排一些通知,我需要从服务器获取一些数据但是当我创建 Alamofire 请求时,surver 会返回数据但 alamofire 不会调用我的编译处理程序 (responseString)

当我的应用程序处于前台时,完全相同的代码可以完美运行。

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

我使用AlamofireNetworkActivityLogger 来检查创建和获取响应的天气,结果是真的。但是我的编译处理程序没有被调用!

在后台使用 Alamofire 时我还应该考虑其他什么?

【问题讨论】:

  • 你有解决办法吗?

标签: ios swift alamofire background-fetch


【解决方案1】:

您是否测试过它是否按照Alamofire network calls not being run in background thread 中的建议工作

我们可能不得不从后台线程而不是主线程开始调用(因为这是默认行为)。

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 2021-01-31
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多