在signalR中调用hub方法 - Objective C

时间:2016-12-15 13:04:52

标签: ios objective-c signalr

我是ios开发的新手。我正在尝试实现Signal R.我试过,我能够连接到集线器。但我不知道如何调用集线器方法CheckWebServiceStatus

我收到错误

  

'SRHubProxy'没有可见的@interface声明选择器'invoke:'

这是我的代码

#import "ViewController.h"
#import "SignalR.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    SRHubConnection *hubConnection = [SRHubConnection connectionWithURLString:@"https://MY HUB URL HERE/"];

    // Create a proxy to the chat service
    SRHubProxy *chat = [hubConnection createHubProxy:@"chatHub"];
    [chat on:@"addMessage" perform:self selector:@selector(addMessage:)];

    // [chat on:@"addMessage" perform:self selector:@selector(addMessage:)];

    // Register for connection lifecycle events
    [hubConnection setStarted:^{
        NSLog(@"Connection Started");
      //  [connection send:@"CheckWebServiceStatus"];
        [chat invoke:@"CheckWebServiceStatus"];

    }];
    [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)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

有人可以告诉我如何使用目标c调用集线器方法。

1 个答案:

答案 0 :(得分:0)

这是一个调用方法的例子

- (void) sendOperatorMessage :(NSString*) visitorId Message:(NSString*) message OperatorId:(NSString*) operatorid Token:(NSString*) ProfileToken SpinnerId:(NSString*) spinnerId CurrentDateTime:(NSString*) currentDateTime{

    [chat invoke:@"sendMessageOperator" withArgs:[NSArray arrayWithObjects:visitorId, message, operatorid, @"false", @"false", @"false", ProfileToken, currentDateTime, spinnerId, nil]];
}