2015-10-18 53 views
0

我正尝试连接到Socket.IO服务器。我使用SWIFT库使用Socket.IO时禁用应用程序传输安全

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://)资源d因为它不安全。临时例外可以通过您的应用程序的Info.plist文件进行配置。

回答

1

然后,也许它后来尝试连接到另一个地址,你没有在info.plist文件中提供的API。
只是暂时的事情,你可以这样做,以消除此传输安全错误:

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 
相关问题