gpt4 book ai didi

ios - Swift 项目中的 SignalR-ObjC

转载 作者:搜寻专家 更新时间:2023-11-01 05:44:10 25 4
gpt4 key购买 nike

我的 swift 项目中的 SignalR-ObjC 有问题。我创建了一个与 SR 到我的中心的连接,代码是:

import UIKit
import SignalR_ObjC


class ViewController: UIViewController, SRConnectionDelegate {


@IBOutlet weak var textFied_Username: UITextField!

@IBOutlet weak var textField_Password: UITextField!

@IBOutlet weak var btn_Login: UIButton!

var hubConnection = SRHubConnection(URLString: "http://myUrl.com");

var hubProxy = SRHubProxy();


var txt_Username : String = "username";
var txt_Password : String = "password";


override func viewDidLoad() {

super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


@IBAction func btn_Login(sender: AnyObject) {




txt_Username = textFied_Username.text!;


txt_Password = textField_Password.text!;


hubProxy = SRHubProxy(connection: hubConnection, hubName: "MyHub");

let signInSelector = Selector("signInResponse:");

hubProxy.on("signIn", perform: self, selector: signInSelector);


hubConnection.delegate = self;


hubConnection.start();

self.SRConnectionDidOpen(hubConnection);





}

func SRConnectionDidOpen(connection: SRConnectionInterface!) {

hubProxy.invoke("SignIn", withArgs: ["username","password"])


}


func signInResponse(response: String) {

NSLog(response);
}

}

连接建立,调用成功,但收不到消息,方法:

hubProxy.on("signIn", perform: self, selector: signInSelector);

不起作用,选择器:

signInSelector

永远不会被调用。谁能帮我解决这个问题??谢谢你,抱歉我的英语不好,我希望问题很清楚。

最佳答案

swift 4、Xcode 9

尝试在 func declarationm 添加@objc 选择器这是我的工作示例:

func configureProxy() {
let proxy: SRHubProxy? = createHubProxy(kHubName) as? SRHubProxy
// we are using proxy-connection, to avoid parsing NSData ourselves.
proxy?.on(kReceivedMessageSignalREventName, perform: self, selector: #selector(self.didReceiveMessage(_:)))
}


@objc func didReceiveMessage(_ message: [AnyHashable: Any]?) {
if (receiveMessageBlock != nil) {
receiveMessageBlock!(message)
}
}

关于ios - Swift 项目中的 SignalR-ObjC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430294/

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