我对ios developpement / siganlr完全陌生。我试图做的是连接signalr-objc客户端以从.net api获取长轮询提要。
它适用于javascript:
var connection = $.hubConnection();
connection.url = "http://HOST:8080/live";
connection.qs = { 'group': 'default' };
connection.start({ transport: ['longPolling'] }).done(function() {
console.log('Proxy Started');
});
var myHubProxy = connection.createHubProxy('quotesHub');
myHubProxy.on('update',callback);
pod文件: 平台:ios,' 6.0' pod' AFNetworking' pod' SignalR-ObjC',' 2.0.0.alpha1'
SRHubProxy *myHub
- (void)viewDidLoad {
[super viewDidLoad];
SRHubConnection *hubConnection = [SRHubConnection connectionWithURL:@"http://HOST:8080/live"];
myHub = [hubConnection createHubProxy:@"quotesHub"];
[hubConnection start];
}
控制台: 2015-02-16 10:02:27.070 BOP [7575:201923]线程{number = 1,name = main}: - [SRHubConnection createHubProxy:] [第90行] [CONNECTION]将创建代理quotesHub 2015-02-16 10:02:27.071 BOP [7575:201923]线程{number = 1,name = main}: - [SRConnection negotiate:] [第145行] [CONNECTION]将进行谈判 2015-02-16 10:02:27.231 BOP [7575:201923]线程{number = 1,name = main}:__ 26- [SRConnection negotiate:] _ block_invoke [第153行] [CONNECTION]协商是成功的NegotiationResponse:的ConnectionId = 3f45c0e5-4d82-4fc6-b93c-899df9fa4d8d ConnectionToken = AQAAANCMnd8BFdERjHoAwE / CL + sBAAAAj7aAvp83K0eLymig4Ji2AQAAAAACAAAAAAAQZgAAAAEAACAAAADDOcCsrRYY6DlcehbqrENsZS8oS0al5bS5 + iB4kfxAxAAAAAAOgAAAAAIAACAAAADX5hJioXnlSWFAeB372DRI + KmNIhKHu0tAZQJv74F5IDAAAABJ8 + 6Xcn9nhSM0uR8OVEP3cRgCaGBBxH1PwVbmIKuAN8SCJSYzvuWxY2CApjh54 / xAAAAAgp7E / TFp1LzCBg366o3o53Pm / hKpd + s8CrlqF / 6DJ + kSIM817FImrLk1nPBI97NH1vg + TiGjReGRojCmARUGiw == URL = / live / signalr / signalr ProtocolVersion = 1.3.0.0 TryWebSockets = 1 2015-02-16 10:02:27.365 BOP [7575:201923]线程{number = 1,name = main}:__ 64- [SRLongPollingTransport poll:connectionData:completionHandler:] _ block_invoke [第115行] [LONG_POLLING] LP接收:{" C":" d-F194B7D3-ESt,0 | ESu,22 | ESv,1 | ESw,0 | ESx,0",&#34 ; G":" AQAAANCMnd8BFdERjHoAwE / CL + sBAAAAj7aAvp83K0eLymig4Ji2AQAAAAACAAAAAAAQZgAAAAEAACAAAADWWDNmvsVMU7xiw3MUzup31k5foUMePnHxGFNk1iYniQAAAAAOgAAAAAIAACAAAACvRs4amrWeEHvEhvruL56d7WU3fcV6 / Lkn2LrMvBehiEAAAACPONM / LfXd9oIuoGyRGST2aPB84UKlLdQU7Bf7ElX4ejaj + i2e105JnxOHys7Ft1NIYrALCIi5kACQeWNCUW8WQAAAAINXqlHul + DNuDfj5VFm / UV9OPyRpElfFkBh59gIt0paKvg4DaGiq5j + WWzEooDMf9Vn7ubPbAdnRCBMslr / BDI ="" M":[{" H":" QuotesHub"" M":"更新"" A":[{"时间&#34 ;:1423857599,"符号":" SKC:AGI""出价":163.5"向":164.25}]},{ " H":" QuotesHub"" M":"更新"" A":[{&#34 ;时间":1424062933,"符号":" SWCO:AGI""出价":53.37,"向":53.48} ]},{" H":" QuotesHub"" M":"更新"" A":[ {"时间":1424062927,"符号":" SBCO:AGI&#3 4;,"出价":61.27"向":61.38}]},{" H":" QuotesHub"&#34 ; M":"更新"" A":[{"时间":1424062946,"符号":" HSI:AGI""出价":24697.0,"向":24707.0}]},{" H":" QuotesHub" " M":"更新"" A":[{"时间":1424062841,"符号&#34 ;: " KOSPI:AGI""出价":250.63"向":250.73}]},{" H":" QuotesHub"" M":"更新"" A":[{"时间":1424062744,"符号与#34;:" NIKK:AGI""出价":18021.0,"向":18031.0}]},{" H&#34 ;: " QuotesHub"" M":"更新"" A":[{"时间":1424062943,& #34;符号":" USDCHF_b""出价":0.92932"向":0.92938}]},{" H&#34 ;:" QuotesHub"" M":"更新"" A":[{"时间":1424062935 "符号":" GBPUSD_b""出价":1.54214"向":1.5422}]},{" H& #34;:" QuotesHub" " M":"更新"" A":[{"时间":1424062934,"符号&#34 ;: " EURUSD_b""出价":1.14146"向":1.14152}]},{" H":" QuotesHub&# 34;," M":"更新"" A":[{"时间":1424062941,"符号&#34 ;:" USDJPY_b""出价":118.593,"向":118.599}]},{" H":" QuotesHub"" M":"更新"" A":[{"时间":1424062937,"符号与#34;:" NZDUSD_b""出价":0.75009"向":0.75015}]},{" H":&# 34; QuotesHub"" M":"更新"" A":[{"时间":1424062941,&#34 ;符号":" AUDUSD_b""出价":0.77845"向":0.77851}]},{" H&#34 ;: " QuotesHub"" M":"更新"" A":[{"时间":1424062893,& #34;符号":" USDCAD_b""出价":1.24344"向":1.2435}]},{" H&#34 ;:" QuotesHub"" M":"更新"" A":[{"时间":1424062921 " S ymbol":" EURGBP_b""出价":0.74015"向":0.74021}]},{" H":& #34; QuotesHub"" M":"更新"" A":[{"时间":1424062947,&# 34;符号":" EURJPY_b""出价":135.37"向":135.376}]},{" H" :" QuotesHub"" M":"更新"" A":[{"时间":1424062941, "符号":" GBPJPY_b""出价":182.888,"向":182.894}]},{" H&# 34;:" QuotesHub"" M":"更新"" A":[{"时间&#34 ;: 1424062936"符号":" CHFJPY_b""出价":127.612,"向":127.618}]},{" H":" QuotesHub"" M":"更新"" A":[{"时间&#34 ;:1424062936,"符号":" EURCHF_b""出价":1.06083"向":1.06089}]},{&# 34; H":" QuotesHub"" M":"更新"" A":[{"时间& #34;:1424062936,"符号":" AUDJPY_b""出价":92.321,"向":92.329}]},{ " H":" QuotesHub"" M":"更新"" A":[{&#34 ;时间":1424062943,"符号":" GBPCHF_b""出价":1.43317"向":1.43324}]} ,{" H":" QuotesHub"" M":"更新"" A":[{& #34;时间":1424062893,"符号":" GBPCAD_b""出价":1.91766,"向":1.91774} ]},{" H":" QuotesHub"" M":"更新"" A":[ {"时间":1424062927,"符号":" GBPAUD_b""出价":1.98093,"向&#34 ;: 1.98098}]},{" H":" QuotesHub"" M":"更新"" A" :[{"时间":1424062944,"符号":" USDCNH_b""出价":6.25113"向&#34 ;:6.25118}]},{" H":" QuotesHub"" M":"更新"" A&# 34;:[{"时间":1424062937,"符号":" XAUUSD_b""出价":1233.25"向& #34;:1233.85}]},{" H":" QuotesHub"" M":"更新"" A":[{ "时间":1424052003,"符号":" XAUEUR_b""出价":1077.9,"向":1078.4 }]},{" H":" QuotesHub"" M":"更新"" A&#34 ;: [{"时间":1424062927,"符号":" XAGUSD_b""出价":17.35"向" :17.41}]},{" H":" QuotesHub"" M":"更新"" A&#34 ;:[{"时间":1423871880,"符号":" XAGEUR_b""出价":15.22"向&# 34;:15.27}]},{" H":" QuotesHub"" M":"更新"" A& #34;:[{"时间":1423868402,"符号":" NDX""出价":4383.99"向":4384.08}]},{" H":" QuotesHub"" M":"更新"&#34 ; A":[{"时间":1424062919,"符号":" NQH""出价":4375.59&# 34;向":4375.68}]},{" H":" QuotesHub"" M":"更新",& #34; A":[{"时间":1424062919,"符号":" NQM""出价":4370.71, "向":43 70.8}]},{" H":" QuotesHub"" M":"更新"" A" :[{"时间":1423673496,"符号":" NQU""出价":4272.21"向&#34 ;:4272.3}]},{" H":" QuotesHub"" M":"更新"" A&# 34;:[{"时间":1423672098,"符号":" NQZ""出价":4260.21"向& #34;:4260.3}]},{" H":" QuotesHub"" M":"更新"" A":[{"时间":0,"符号":"富时""出价":0.0&#34 ;向":0.0}]},{" H":" QuotesHub"" M":"更新"&# 34; A":[{"时间":0,"符号":" DAX""出价":0.0,& #34;向":0.0}]}]} 2015-02-16 10:02:27.368 BOP [7575:201923]线程{number = 1,name = main}:__ 73- [SRAutoTransport start:connectionData:transportIndex:completionHandler:] _ block_invoke [Line 123] [AUTO_TRANSPORT]确实设置了主动传输 2015-02-16 10:02:27.433 BOP [7575:201923]线程{number = 1,name = main}:__ 64- [SRLongPollingTransport poll:connectionData:completionHandler:] _ block_invoke [第115行] [LONG_POLLING] LP接收:{" C":" d-F194B7D3-ESt,0 | ESu,22 | ESv,2 | ESw,0 | ESx,0",&#34 ; S":1," M":[]}
我一直 2015-02-16 11:24:23.902 BOP [8369:221220]线程{number = 1,name = main}:__ 64- [SRLongPollingTransport poll:connectionData:completionHandler:] _ block_invoke [Line 115] [LONG_POLLING] LP接收:{" C":" d-F194B7D3-ESy,0 | ESz,22 | ES0,2 | ES1,0"," M& #34;:[]} 每1/2分钟而不是数据Feed。
我不知道现在发生了什么以及如何让它发挥作用。
有人可以帮忙吗?提前谢谢。
答案 0 :(得分:0)
每1/2分钟后收到的消息。状态就像你连接SignalR,即要连接的HUB名称。在你的 案例是" quotesHub"。
现在你必须调用hub invoke方法。 (方法名称在.net端编写脚本我们必须调用该函数)
让我们举个例子:有一个函数名称为"发送"在asp.net脚本端。对于发送消息,我必须调用该函数。该函数中使用了两个参数。首先是名字,第二是消息。
通过以下代码,我可以做那件事
NSArray * ar = [[NSArray alloc] initWithObjects:@"Andrew Taylor",@"Hi", nil];
[_hub invoke:@"send" withArgs:ar completionHandler:^(id response)
{
NSLog(@"hubResult %@",response);
}];