gpt4 book ai didi

ios - 'PusherSwift' 验证未在 swift 中调用

转载 作者:行者123 更新时间:2023-12-05 05:58:49 24 4
gpt4 key购买 nike

我正在尝试使用“AuthRequestBuilderProtocol”来验证 Pusher 连接。但它没有被调用,我创建了一个继承自 AuthRequestBuilderProtocol 的 AuthRequestBuilder 类,如下面的代码

class AuthRequestBuilder: AuthRequestBuilderProtocol {
func requestFor(socketID: String, channelName: String) -> URLRequest? {
print("HELLO FROM AUTH REQUEST BUILDER!")
let request = NSMutableURLRequest(url: URL(string: "https://xxxxxxxxxx/broadcasting/auth")!)
request.httpMethod = "POST"
request.httpBody = "socket_id=\(socketID)&channel_name=\(channelName)".data(using: String.Encoding.utf8)
print("socketID: \(socketID), ChannelName: \(channelName)")
request.addValue("Bearer " + UserDefaults.standard.retreiveUserAccessToken(), forHTTPHeaderField: "Authorization")
return request as URLRequest
}

在主 Controller 中我定义了以下变量

var client: Pusher?
var channel: PusherChannel?
var options: PusherClientOptions?
var appKey: String = "xxxx"

在 viewDidLoad 中我定义了以下内容:

    override func viewDidLoad() {
super.viewDidLoad()
options = PusherClientOptions(
authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder()),
autoReconnect: true, host: .host("xxxxxxxxxx"),
port: 6001,
path: "/",
activityTimeout: 10
)
client = Pusher(withAppKey: appKey, options: options!)
client?.connection.delegate = self
channel = client?.subscribeToPresenceChannel(channelName: "presence-Room.\(idOfRooms ?? 0)")
client?.connect()
print(channel?.name ?? "")
print(channel?.subscribed ?? "")
print(channel?.type ?? "")
print(channel?.unsentEvents ?? "")

// bind to all events globally
let _ = client?.bind(eventCallback: { (event: PusherEvent) in
var message = "Received event: '\(event.eventName)'"

if let channel = event.channelName {
message += " on channel '\(channel)'"
}
if let userId = event.userId {
message += " from user '\(userId)'"
}
if let data = event.data {
message += " with data '\(data)'"
}

print(message)
})}

问题是当我在 viewDidLoad 中调用时 AuthRequestBuilder 没有被调用,所以我在订阅状态 channel 时遇到了问题,知道如何解决这个问题

最佳答案

我上面提供的所有方法都是正确的!问题是后端服务器版本与最新版本的 PusherSwift 不兼容,所以我从 10.0.0 降级到 8.0.0

关于ios - 'PusherSwift' 验证未在 swift 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68359414/

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