2016-12-30 39 views
1

喜IAM的新目標C和IOS信號R - 獲得的第二個參數

我正在開發使用這種[信號R庫]聊天應用[1]

我能夠連接,併成功地調用沒有任何問題。但我的問題是,我正在訂閱hub方法newVisitorNotification像這樣。

[chat on:@"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 

回答

1

selector是不對的。 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); 

}