I'm looking to figure out how to correctly join groups as SignalR-ObjectiveC is not very well documented. I have set up my application to communicate via SignalR in the following way:
-(void)ConnectSignalR{ // Connect to the service SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"xxx"]; // Register for connection lifecycle events [hubConnection setStarted:^{ NSLog(@"Connection Started"); }]; [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)addMessage:(NSString *)message { // Print the message when it comes in NSLog(@"%@", message); }
I then call these methods by doing the following in my main view controller:
-(void)SignalR{ WebServices *services = [[WebServices alloc] init]; [services ConnectSignalR]; [services callGetSRGroupNames:^(NSMutableArray *resultsArray) { NSLog(@"SR GROUP NAMES: %@", resultsArray); SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"xxx"]; int i; for (i = 0; i < [resultsArray count]; i++) { [hubConnection setGroupsToken:resultsArray[i]]; } }]; }
Is this correct? I receive the following back but am not sure its correct:
WS: websocket did receive: {"C":"s-0,94445","S":1,"M":[]}
1 Answers
Answers 1
Joining to a group is a server side thing. You need to create a hub method (server side) that adds a connection to a group and then invoke this hub method from the client. Take a look at this article for more details.
0 comments:
Post a Comment