简体   繁体   English

无法使用后台配置创建 URLSessionWebSocketTask

[英]Unable to create URLSessionWebSocketTask with background configuration

error: Execution was interrupted, reason: signal SIGABRT.错误:执行被中断,原因:信号 SIGABRT。 The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.进程一直停留在被中断的地方,在表达式求值前使用“thread return -x”返回state。

I'm trying to create URLSessionWebSocketTask with backdround configuration in Playground, but unfortunately i'm getting above mentioned error我正在尝试在 Playground 中使用背景配置创建URLSessionWebSocketTask ,但不幸的是我遇到了上述错误

import Foundation

let urlSession = URLSession(configuration: .background(withIdentifier: "___ID___"))
let webSocketTask = urlSession.webSocketTask(with: URL(string: "wss://echo.websocket.org")!)

I get it,我得到它,

https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background https://developer.apple.com/documentation/foundation/url_loading_system/downloading_files_in_the_background

Comply with Background Transfer Limitations遵守后台传输限制

With background sessions, the actual transfer is performed by a process that is separate from your app's process.对于后台会话,实际传输由与您的应用程序进程分开的进程执行。 Because restarting your app's process is fairly expensive, a few features are unavailable, resulting in the following limitations:由于重新启动您的应用程序的进程相当昂贵,因此一些功能不可用,从而导致以下限制:

  • The session must provide a delegate for event delivery. session 必须为事件传递提供委托。 (For uploads and downloads, the delegates behave the same as for in-process transfers.) (对于上传和下载,委托的行为与进程内传输相同。)

  • Only HTTP and HTTPS protocols are supported (no custom protocols).仅支持 HTTP 和 HTTPS 协议(无自定义协议)。

  • Redirects are always followed.始终遵循重定向。 As a result, even if you have implemented urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:), it is not called.结果,即使你已经实现了 urlSession(_:task:willPerformHTTPRedirection:newRequest:completionHandler:),它也不会被调用。

  • Only upload tasks from a file are supported (uploads from data instances or a stream fail after the app exits).仅支持从文件上传任务(应用退出后从数据实例或 stream 上传失败)。

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

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