嗨,我是 Objective C 和 ios 的新手
我正在使用这个 [signal R 库][1] 开发一个聊天应用程序
我能够毫无问题地连接和调用 successFully。但我的问题是,我订阅了一个像这样的 hub 方法 newVisitorNotification。
[聊天:@"newVisitorNotification"perform:self selector:@selector(responsenewVisitorNotification:)];
当新消息到达 newVisitorNotification 时,它会将数据发送到 responsenewVisitorNotification
。该方法发送两个参数
2016-12-30 12:21:52.389411 Chat System[451:79343] CONNECTION: connection did receive data {
A = (
"6279b7ce-20bf-40f7-b8e8-8f987e209fbf",
baman26
);
H = ChatHub;
M = newVisitorNotification;
}
但是我的方法只能接收一个参数。
-(void) responsenewVisitorNotification:(NSString *) response {
NSLog(@"Inside response incomming chat");
NSLog(@"Response incomming Chat : %@", response);
}
谁能帮我获取 responsenewVisitorNotification
中的第二个参数。
这是我的完整代码
- (void) StartConnection {
self.CONNECTIONSTATUS = NO;
[self setHubEnvironmentURL];
hubConnection = [SRHubConnection connectionWithURLString:environmentURL];
chat = [hubConnection createHubProxy:@"chatHub"];
[chat on:@"serviceStatus" perform:self selector:@selector(getServiceStaus:)];
[chat on:@"newVisitorNotification" perform:self selector:@selector(responsenewVisitorNotification:)];
// Register for connection lifecycle events
[hubConnection setStarted:^{
NSLog(@"Connection Started ");
NSLog(@"**************************************************************************");
NSLog(@"****************************** Starting Invoke ***************************");
NSLog(@"**************************************************************************");
[self invokeIncommingChats:ProfileId Company:companyId Token:profileToken];
self.CONNECTIONSTATUS = YES;
}];
[hubConnection setReceived:^(NSString *message) {
NSLog(@"Connection Recieved Data: %@",message);
}];
[hubConnection setConnectionSlow:^{
NSLog(@"Connection Slow");
}];
[hubConnection setReconnecting:^{
NSLog(@"Connection Reconnecting");
}];
[hubConnection setReconnected:^{
NSLog(@"Connection Reconnected");
}];
[hubConnection setClosed:^{
NSLog(@"Connection Closed");
}];
[hubConnection setError:^(NSError *error) {
NSLog(@"Connection Error %@",error);
}];
// Start the connection
[hubConnection start];
}
- (void)getServiceStaus:(NSString *)message {
NSLog(@"Service Status : %@", message);
}
-(void) responsenewVisitorNotification:(NSString *) response {
NSLog(@"Inside response incomming chat");
NSLog(@"Response incomming Chat : %@", response);
}
[1]: https://github.com/DyKnow/SignalR-ObjC
最佳答案
您的选择器
不正确。 Read this.
[chat on:@"newVisitorNotification" perform:self
//selector:@selector(responsenewVisitorNotification::)]
selector:@selector(responsenewVisitorNotification:and:)]
然后:
-(void) responsenewVisitorNotification:(NSString *) response1 :(NSString*)response2 {
NSLog(@"Inside response incomming chat");
NSLog(@"Response field 1 incomming Chat : %@", response1);
NSLog(@"Response field 2 incomming Chat : %@", response2);
}
关于ios - 信号 R - 获取第二个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41392129/