【问题标题】:Disable App Transport Security while working with Socket.IO使用 Socket.IO 时禁用 App Transport Security
【发布时间】: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


    【解决方案1】:

    然后它可能会尝试使用您在info.plist 文件中未提供的另一个地址连接到 API。
    作为临时的事情,您可以这样做,以消除此传输安全错误:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    

    【讨论】:

      猜你喜欢
      • 2018-01-27
      • 2016-08-14
      • 2016-07-12
      • 2016-02-10
      • 2016-01-20
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 2018-04-28
      相关资源
      最近更新 更多