io socket为应用程序传输安全抛出错误

2022-01-28 13:42:51 标签 iosswiftsocket.ioinfo.plist

我试图用SocketIO的帮助连接套接字,但它抛出错误为错误SocketEngine:资源不能被加载,因为应用程序传输安全策略需要使用安全连接。甚至我都在我的信息里定义了运输安全。plist文件。

info。plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleVersion</key>
    <string>1</string>
</dict>
</plist>
controller code
//
//  ViewController.swift
//  socketioDemo
//
//  Created by developer on 9/12/21.
//
import UIKit
import SocketIO
final class Service: ObservableObject {
    private var manager = SocketManager(socketURL: URL(string: "ws://localhost:3000")!, config: [.log(true), .compress])
    var messages = [String]()
    init() {
        let socket = manager.defaultSocket
        socket.on(clientEvent: .connect, callback: { (data, ack) in
            print("connected to wss")
            socket.emit("Node js server port", "Hi Node Js Server")
        })
        socket.on("iOS client port") { [weak self] (data, ack) in
            if let data = data[0] as? [String: String], let rawMessage = data["msg"] {
                self?.messages.append(rawMessage)
            }
            
        }
        
        socket.connect()
    }
}
class ViewController: UIViewController {
    
    var service = Service()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    
}

###检查URL (socketURL)

确保web中的suer有SSL证书

阅读全文

▼ 版权说明

相关文章也很精彩
推荐内容
更多标签
相关热门
全站排行
随便看看

错说 cuoshuo.com —— 程序员的报错记录

部分内容根据CC版权协议转载;网站内容仅供参考,生产环境使用务必查阅官方文档

辽ICP备19011660号-5

×

扫码关注公众号:职场神器
发送: 1
获取永久解锁本站全部文章的验证码