2017-02-09 3 views
1

私は、SignalR-ObjectiveCがあまりうまく文書化されていないので、正しくグループに参加する方法を見つけようとしています。私は、次のようにSignalRを介して通信するために自分のアプリケーションを設定している:SignalR Objective-Cを使ってグループに加入するには?

-(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); 
} 

私はその後、私のメインのビューコントローラで次の手順を実行して、これらのメソッドを呼び出します。

-(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]]; 
     } 
    }]; 
} 

は、この正しいですか?私は次のようなことを受け取りましたが、正しいかどうかはわかりません:

WS: websocket did receive: {"C":"s-0,94445","S":1,"M":[]} 

答えて

2

グループに参加することはサーバー側のことです。グループへの接続を追加し、このハブ・メソッドをクライアントから呼び出すハブ・メソッド(サーバー側)を作成する必要があります。詳細はthis articleをご覧ください。

+0

クライアントからハブ・メソッドを呼び出す方法について詳しく説明できますか? – arcade16

+1

サンプル中に見つかりました。 https://github.com/DyKnow/SignalR-ObjC/blob/c412cc38618b27c83fe170eaa9da95aa0c7eb42a/Example/Networking/DrawingPadConnection.m#L48 – Pawel

+0

あなたは男性の中の神です、ありがとうございます! – arcade16

関連する問題