EbrahimTahernejad / Tun2SocksKit

Tun2Socks framework repository
50 stars 32 forks source link

传入字符串时报错: Type 'String' has no member 'string' #5

Closed Cyberbolt closed 3 months ago

Cyberbolt commented 3 months ago

您好,请问不能直接传入字符串作为配置吗?

源码

//
//  tun2socks.swift
//  phone
//
//  Created by Cyberbolt on 2024/2/23.
//

import Foundation
import NetworkExtension
import Tun2SocksKit

class PacketTunnelProvider: NEPacketTunnelProvider {
    override func startTunnel(options: [String : NSObject]?, completionHandler: @escaping (Error?) -> Void) {
        // 这里配置你的 TUN 设备和其他网络设置

        // 示例:调用 Socks5Tunnel 来转发流量
        let config = "tunnel:\n  mtu: 1500\n\nsocks5:\n  port: 7890\n  address: 127.0.0.1\n  udp: 'udp'\n\nmisc:\n  task-stack-size: 20480\n  connect-timeout: 5000\n  read-write-timeout: 60000\n  log-file: stderr\n  log-level: debug\n  limit-nofile: 65535"

        Socks5Tunnel.run(withConfig: .string(content: config)) { code in
            if code == 0 {
                print("Socks5Tunnel started successfully")
            } else {
                print("Failed to start Socks5Tunnel with error code: \(code)")
            }
        }

        completionHandler(nil)
    }

    override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
        // 停止任何网络活动,清理资源
        completionHandler()
    }
}

报错行

Socks5Tunnel.run(withConfig: .string(content: config)) { code in

报错内容

Type 'String' has no member 'string'
EbrahimTahernejad commented 3 months ago

which version are you using?

3.6.7: (withConfig: Config) before 3.6.7: (withConfig: String)

the string is the path to config file

Cyberbolt commented 3 months ago

@EbrahimTahernejad

Can I directly pass in the string of the configuration file instead of the path to the configuration file?

EbrahimTahernejad commented 3 months ago

Only from version 3.6.7

https://github.com/EbrahimTahernejad/Tun2SocksKit/releases/tag/3.6.7