0

I'm making an HTTPS request that's initiated from a UNUserNotification action, so it performs with my app running in the background. I suspect that this feature isn't supported by Siesta, in which case I'll make a feature request! But first I want to see if I'm correct about that.

When I set up & make a request in the background using Siesta, no request appears to be made until I open my app, when I get a URLSessionTask error code -1003 "HTTP load failed" with message: URL Session Task Failed: A server with the specified hostname could not be found..

This is the exact same behavior I see if I use plain URLSession to make requests, without configuring the session for background execution using the boilerplate:

let config = URLSessionConfiguration.background(withIdentifier: String(format: "%f", Date().timeIntervalSinceReferenceDate))

config.isDiscretionary = isDiscretionary
config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.sessionSendsLaunchEvents = true
config.timeoutIntervalForResource = backgroundTimeoutInterval

return URLSession(configuration: config,
                  delegate: self,
                  delegateQueue: .main)

Is there an out-of-the-box way to get this behavior in Siesta?

4

1 回答 1

0

是的,Siesta 目前不正式支持后台请求,尽管它也没有正式排除它们。

尚不完全清楚后台请求在 Siesta 中的含义。它是一个内存缓存,那么请求的数据到哪里去了?然而,Siesta 的持久缓存支持将很快从“自己动手”转变为“开箱即用”,届时后台请求将变得更加引人注目。

您应该能够URLSession像上面的示例一样将配置为后台请求的 Siesta 服务构造函数传递给 Siesta,并且 Siesta 会像以往一样愉快地使用它来发出请求。不太清楚的是当这些响应到达时应该发生什么;您将在必要时坚持响应。

于 2018-03-07T02:58:19.767 回答