0

在我们使用 signalR-Objc 和 CocoaPods(管理依赖项)的聊天应用程序上工作。从https://github.com/DyKnow/SignalR-ObjC下载 SignalR_Objc 现在我可以使用这些行与服务器建立连接

@interface AQViewController : UIViewController<SRConnectionDelegate>
{
    SRHubConnection *connection;
    SRHubProxy *hub;
}



@implementation AQViewController

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

    NSString *server = [Router sharedRouter].server_url;
    connection = [SRHubConnection connectionWithURL:server];

    hub = [connection createHubProxy:@"ConvoService"];
    [connection setDelegate:self];

    [connection start];

 }

连接也建立起来没有问题

但是当我在服务器上调用某个方法时,它被调用了,因为我可以看到日志服务器并且数据库也填充了相应的数据..但问题是我的 SRHubConnection 委托方法没有被调用。

//代码

@interface AQViewController : UIViewController<SRConnectionDelegate>
{
    SRHubConnection *connection;
    SRHubProxy *hub;
 }


-(IBAction)connect:(id)sender;
@end



#import "AQViewController.h"
#import "Router.h"

@interface AQViewController ()

@end

@implementation AQViewController

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


    connection = [SRHubConnection    connectionWithURL:@"http://medcomm.w08dev2.in.aquevix.com"];

   hub = [connection createHubProxy:@"ConvoService"];
   [connection setDelegate:self];

    [connection start];

}



-(IBAction)connect:(id)sender{
       NSString *authKey = @"815f35c0-1cfc-4154-a0c8-7ccb80465c6f23b7d170-3fa4-4a56-   ad50-27c1d5f0390e";

    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];

    [dic setValue:authKey forKey:@"AuthKey"];

    NSArray *arr = [NSArray arrayWithObjects:dic, nil];
    NSLog(@"arr %@",arr);

   [hub invoke:@"Connect" withArgs:arr completionHandler:^(id u){
    NSString *str = (NSString *)u;


    NSLog(@"Got connect response %@",str);
    }];

}

//这些委托在服务器上调用方法时不会被调用,而是在请求连接时被调用

#pragma mark - #pragma mark SRConnection 代表

- (void)SRConnectionDidOpen:(SRConnection *)connection
 {
   //AQSK
   NSLog(@"get connected using HubConnection");


 }

  - (void)SRConnection:(SRConnection *)connection didReceiveData:(NSString *)data
  {
     //AQSK

     NSLog(@"data recieved %@",data);

  }

   - (void)SRConnectionDidClose:(SRConnection *)connection
  {
     NSLog(@"close");
  }

   - (void)SRConnection:(SRConnection *)connection didReceiveError:(NSError *)error
  {
     NSLog(@"error%@",error.description);
   }

任何想法 ??请帮忙。

4

0 回答 0