2015-10-18 56 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> 
相關問題