【发布时间】:2015-10-18 17:01:20
【问题描述】:
我正在尝试连接到 Socket.IO 服务器。我正在使用 swift 库
https://github.com/socketio/socket.io-client-swift
这是我的示例代码
NSString *url = [NSString stringWithFormat:@"myIP:443];
self.socket = [[SocketIOClient alloc] initWithSocketURL:url opts:nil];
[socket on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
NSLog(@"socket connected");
}];
[socket on:@"currentAmount" callback:^(NSArray* data, SocketAckEmitter* ack) {
double cur = [[data objectAtIndex:0] floatValue];
[socket emitWithAck:@"canUpdate" withItems:@[@(cur)]](0, ^(NSArray* data) {
[socket emit:@"update" withItems:@[@{@"amount": @(cur + 2.50)}]];
});
[ack with:@[@"Got your currentAmount, ", @"dude"]];
}];
[socket connect];
这是我在 plist 中使用的内容
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>xx.xx.xxx.xxx</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
我还在继续
App Transport Security 已阻止明文 HTTP (http://) 资源加载,因为它不安全。可以通过应用的 Info.plist 文件配置临时异常。
【问题讨论】:
标签: ios objective-c socket.io