我正在尝试将UDP数据报发送到服务器。如果我的iOS设备连接到Wi-Fi,则以下代码可以正常工作,但是当我将其切换到运营商网络(T-Mobile)时,它会失败,并显示错误Error code: -9980(0x-26FC), Operation not permitted
。
我正在使用BlueSocket。我浏览了他们的问题页面,但似乎没有人遇到与我相同的问题。
此错误发生在我的物理设备(iPhone SE, iOS 12.1
)上。无论我是通过Wi-Fi连接还是使用与我遇到问题的同一部物理电话(例如,模拟器–>
MacBook –>
iPhone)设置热点,模拟器(XR)都可以正常工作。
public func connect() {
mConnect = true
let queue1: DispatchQueue? = DispatchQueue.global(qos: .userInteractive)
let queue2: DispatchQueue? = DispatchQueue.global(qos: .userInteractive)
guard let pQueue = queue1 else {
print("Unable to access global interactive QOS queue")
return
}
guard let pQueue2 = queue2 else {
print("Unable to access global interactive QOS queue2")
return
}
do {
// Create the socket..
mVideoSocket = try Socket.create(family: .inet, type: .datagram, proto: .udp)
pQueue.async { [unowned self, mVideoSocket] in
do {
while self.mConnect {
print("Listening...")
var data = Data()
let (bytesRead, addressObj) = try self.mVideoSocket.listen(forMessage: &data, on: Int(self.mLocalPort))
let payload = String(data: data, encoding: String.Encoding.utf8)!
var payloadSplit = payload.components(separatedBy: ":")
let (address, port) = Socket.hostnameAndPort(from: addressObj!)!
print("Bytes read = \(bytesRead), Address = \(address), Port = \(port), Payload = \(payload)")
if payloadSplit[0] == "1" {
//from server, get ip:port
print("Exchange")
self.mVideoIp = payloadSplit[1]
self.mVideoPort = Int32(payloadSplit[2])!
try self.mVideoSocket.write(from: "punch", to: Socket.createAddress(for: self.mVideoIp, on: self.mVideoPort)!)
}
else if payloadSplit[0] == "2" {
//from punching!
print("Got Punched from address=\(address), port=\(port)")
try self.mVideoSocket.write(from: "punched", to: Socket.createAddress(for: address, on: port)!)
}
else if payloadSplit[0] == "3" {
//got punched
print("Device Acked Punch")
}
}
} catch let error {
print("testListenUDP1 Error reported: \(error)")
}
}
usleep(1000000)
pQueue2.async { [unowned self, mVideoSocket] in
do {
if self.mMode == .recorder {
try self.mVideoSocket.write(from: "recorder", to: Socket.createAddress(for: "MyHost", on: 5001)!)
}
else {
try self.mVideoSocket.write(from: "viewer", to: Socket.createAddress(for: "MyHost", on: 5001)!)
}
} catch let error {
print("overhere: \(error)")
}
}
} catch let error {
print("testListenUDP2 Error reported: \(error)")
}
}