gpt4 book ai didi

ios - 无法使用后台配置创建 URLSessionWebSocketTask

转载 作者:行者123 更新时间:2023-11-29 05:26:44 27 4
gpt4 key购买 nike

error: Execution was interrupted, reason: signal 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.

我正在尝试在 Playground 中使用 backdround 配置创建 URLSessionWebSocketTask ,但不幸的是我遇到了上述错误

import Foundation

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

最佳答案

我明白了,

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

遵守后台传输限制

对于后台 session ,实际传输是由与应用进程分开的进程执行的。由于重新启动应用程序的进程相当昂贵,因此一些功能不可用,从而导致以下限制:

  • session 必须提供事件传递的委托(delegate)。 (对于上传和下载,委托(delegate)的行为与进程内传输相同。)

  • 仅支持 HTTP 和 HTTPS 协议(protocol)(无自定义协议(protocol))。

  • 始终遵循重定向。结果,即使你有实现的urlSession(_:任务:willPerformHTTPRedirection:newRequest:completionHandler:),它没有被调用。

  • 仅支持从文件上传任务(从数据上传应用退出后实例或流失败)。

关于ios - 无法使用后台配置创建 URLSessionWebSocketTask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58096154/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com