Network connections send and receive data using transport and security protocols.

Posts under Network tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Xcode 13 beta | Failed to build module 'Network' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
I have a project which has iOS 10.0 deployment target in which I import Network framework in some class and conditionally using it depending on the host app’s iOS version.   With Xcode 13 beta 4(13A5201i), I am able to compile and run the project successfully while debugging on iPhone device but it gives below error. This was working fine with Xcode 12.5.1 /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/lib/swift/Network.swiftmodule/armv7-apple-ios.swiftinterface:1254:19: 'NWConnection' is only available in iOS 12.0 or newer /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/lib/swift/Network.swiftmodule/armv7-apple-ios.swiftinterface:1254:1: Add @available attribute to enclosing extension /Application/NWBrowserManager.swift:10:8: Failed to build module 'Network' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
12
0
10k
Nov ’23
iOS HTTP Proxy Settings Ineffective
My issue: I go through Settings>Wi-fi>The i button next to my network name>Configure Proxy>Manual. When entering my proxy's hostname, port and authentication, everything seems fine. It allows me to save the info and gives me no error prompts. However, the proxy does not actually work. The same one works perfectly when using chrome extensions to connect to it. I am 100% sure I am entering the information correctly. Questions: Does anyone else experience this issue? If so, do you know of why? If so, do you know a workaround? Device Info: iPhone Xs on iOS 15.4.1 (this issue has persisted since I first tried on 14.8, and was not fixed by installing the update.) Network Info: IP and DNS are on automatic configuration
6
1
5.1k
Sep ’23
Networking Resources
General: TN3151 Choosing the right networking API Networking Overview document — Despite the fact that this is in the archive, this is still really useful. TLS for App Developers DevForums post Choosing a Network Debugging Tool documentation WWDC 2019 Session 712 Advances in Networking, Part 1 — This explains the concept of constrained networking, which is Apple’s preferred solution to questions like How do I check whether I’m on Wi-Fi? TN3135 Low-level networking on watchOS Adapt to changing network conditions tech talk Foundation networking: DevForums tags: Foundation, CFNetwork URL Loading System documentation — NSURLSession, or URLSession in Swift, is the recommended API for HTTP[S] on Apple platforms. Network framework: DevForums tag: Network Network framework documentation — Network framework is the recommended API for TCP, UDP, and QUIC on Apple platforms. Network Extension (including Wi-Fi on iOS): See Network Extension Resources Wi-Fi Fundamentals Wi-Fi on macOS: DevForums tag: Core WLAN Core WLAN framework documentation Wi-Fi Fundamentals Secure networking: DevForums tags: Security Apple Platform Security support document Preventing Insecure Network Connections documentation — This is all about App Transport Security (ATS). Available trusted root certificates for Apple operating systems support article Requirements for trusted certificates in iOS 13 and macOS 10.15 support article About upcoming limits on trusted certificates support article Apple’s Certificate Transparency policy support article Technote 2232 HTTPS Server Trust Evaluation Technote 2326 Creating Certificates for TLS Testing QA1948 HTTPS and Test Servers Miscellaneous: More network-related DevForums tags: 5G, QUIC, Bonjour On FTP DevForums post Using the Multicast Networking Additional Capability DevForums post Investigating Network Latency Problems DevForums post Local Network Privacy FAQ DevForums post Extra-ordinary Networking DevForums post Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com"
0
0
2.2k
Feb ’24
accept incoming network connections in simulator - xcode 13.4.1
Does anyone know how to rid of this message? It is happening every time I build a project using the simulator with the following versions: xCode 13.4.1 mac Monterey 12.4. I didn't see this behavior in Xcode's previous versions. The issue seems to be because it is adding a new application every time I build the project into the firewall app list. (image below) Any tips on how to fix this?
5
4
1.8k
Dec ’23
How to handle IPv6 link-local addresses in iOS 16?
Our (legacy) code to communicate with peripherals on local IPv6 networks (LAN) adds the zone identifier / interface name ("%en0") to link-local IP addresses (FE80::/10) discovered via SSDP. SSDP is implemented using CocoaAsyncSocket - yes, that part of our code is old... (from before the introduction of the iOS 12+ Network framework). We use these modified IP addresses as the host component of a URL in a URLSession.dataTask. To insert the zone identifier we are using URLComponents (we modify the host and then request the string). This worked fine in iOS 15 and below, but no longer works in iOS 16 (Beta 1/2/3); the host is empty after inserting %en0 in the most recent beta. We have reported this via FB10549269, but from the answer it is unclear to me whether Apple is planning to fix this ("Resolution: Potential fix identified"), or we are doing it wrong. How should we handle IPv6 link-local addresses in iOS 16? (when using URLSession instead of Network) PS: We recently dropped support for iOS 12, but we still need to support iOS 13 and up
3
0
1.8k
Aug ’23
NWPathMonitor returns .unsatisfied the WiFi is back on simulator
I'm testing network loss handling in my app on the simulator. Turning WiFi OFF triggers pathUpdateHandler with .unsatisfied status. Turning WiFi back to ON triggers pathUpdateHandler with .unsatisfied status again. I noticed that pathUpdateHandler is triggered right after I enabled WiFi, but before WiFi actually connects to the network. When the laptop is actually connected to the WiFi network - pathUpdateHandler isn't triggered, so my app stays in "offline" mode permanently. networkMonitor.pathUpdateHandler = { [weak self] path in guard let self = self else { return } DispatchQueue.main.async { if path.status == .satisfied { self.status = .connected } else { print(path.unsatisfiedReason) self.status = .disconnected } } } monitor.start(queue: queue) networkMonitor is retained by my DIContainer
2
0
2.0k
Aug ’23
Unrelated 3rd party apps interfering with NWConnectionGroup's state
Description: Using the Network framework, SDDP discovery will fail while 3rd party apps are running in the background The 3rd party apps in question are (presumably) using the CocoaAsyncSocket library to perform SSDP discoveries on WiFi. How to reproduce Test Setup: For the 3rd party app, you can use https://apps.apple.com/us/app/web-video-cast-browser-to-tv/id1400866497 The simplistic test app referenced below can be installed from: https://github.com/tifroz/SSDPTest You must have the multicast entitlement (https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast) Test steps: On the test device, install a 3rd party app that uses the CocoaAsyncSocket library to performs SSDPdiscovery. Restart the test device to clear any existing 3rd party apps/processes Run this test app on the device, the status should be ready Kill the test app Start the 3rd party app that uses the CocoaAsyncSocket library, then send it to the background (without killing it) after a few seconds Start the test app, this time the status should be (failed, address already in use) Optionally, kill the test app + the 3rd party app, then start the test app again (status should be ready) Question: Is there a workaround?
10
0
830
Oct ’23
Network Framework not picking WatchOS 9+
As you can see in this open source repository, I am trying to test out the code provided when you download the Apple sample "Building a custom peer-to-peer protocol" I bought a new Apple TV in order to work with this. But I have had so many issues! First I realized that the functionality is only available from WatchOS 9 or greater, but my Apple Watch 3 won't update to WatchOS 9. Then I got another watch, but it had to be updated. Then had to turn on the Developer Mode and then I was having a issues where it kept saying that the phone & watch needed to be unlocked, over and over -.-. Then finally after building the app on the watch from my computer using Xcode (latest), the problem I am now having is that the app on the AppleTV only detects the phones in the network, and not this new Apple Watch. -,- So now I just have a bunch of new technology that is doing nothing I have read through so many tutorials but can't tell why it doesn't detect it. It seems like the DDDevicePickerViewController is not returning the watch. The other question I have is, can I use the Network Framework to connect to multiple devices at the same time? (Think Texas hold em poker on Apple TV but with cards on each player's phone)
3
0
1.8k
Oct ’23
how to sort the ip adresses returning from getaddrinfo() like /etc/gai.conf in linux
This is happening Mac M1 Monterey OS .Environment supports both IPv4 and IPV6. When a http client calls gettaddrinfo() it is returning both IPv6,IPv4 IPs . first v6 IPs and then v4 IPs. We need to have a way to sort gettaddrinfo() output to get v4 ip first and then v6. We tried changing DNS order with scutil by putting v4 DNS first , but still getaddrInfo() listing v6 IPs first . In linux there is a way to control gettaddrinfo() o/p with /etc/gai.conf https://man7.org/linux/man-pages/man5/gai.conf.5.html . In Mac I did not find any option like this , scutil changing order DNS is not effective . can you tell us what is way to do this in MAC OSx ?
6
0
1.8k
Feb ’24
iOS Network Signal Strength
This issue has cropped up many times here on DevForums. Someone recently opened a DTS tech support incident about it, and I used that as an opportunity to post a definitive response here. If you have questions or comments about this, start a new thread and tag it with Network so that I see it. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com" iOS Network Signal Strength The iOS SDK has no general-purpose API that returns Wi-Fi or cellular signal strength in real time. Given that this has been the case for more than 10 years, it’s safe to assume that it’s not an accidental omission but a deliberate design choice. For information about the Wi-Fi APIs that are available on iOS, see TN3111 iOS Wi-Fi API overview. Network performance Most folks who ask about this are trying to use the signal strength to estimate network performance. This is a technique that I specifically recommend against. That’s because it produces both false positives and false negatives: The network signal might be weak and yet your app has excellent connectivity. For example, an iOS device on stage at WWDC might have terrible WWAN and Wi-Fi signal but that doesn’t matter because it’s connected to the Ethernet. The network signal might be strong and yet your app has very poor connectivity. For example, if you’re on a train, Wi-Fi signal might be strong in each carriage but the overall connection to the Internet is poor because it’s provided by a single over-stretched WWAN. The only good way to determine whether connectivity is good is to run a network request and see how it performs. If you’re issuing a lot of requests, use the performance of those requests to build a running estimate of how well the network is doing. Indeed, Apple practices what we preach here: This is exactly how HTTP Live Streaming works. Keep in mind that network performance can change from moment to moment. The user’s train might enter or leave a tunnel, the user might walk into a lift, and so on. If you build code to estimate the network performance, make sure it reacts to such changes. But what about this code I found on the ’net? Over the years various folks have used various unsupported techniques to get around this limitation. If you find code on the ’net that, say, uses KVC to read undocumented properties, or grovels through system logs, or walks the view hierarchy of the status bar, don’t use it. Such techniques are unsupported and, assuming they haven’t broken yet, are likely to break in the future. But what about Hotspot Helper? Hotspot Helper does have an API to read Wi-Fi signal strength, namely, the signalStrength property. However, this is not a general-purpose API. Like the rest of Hotspot Helper, this is tied to the specific use case for which it was designed. This value only updates in real time for networks that your hotspot helper is managing, as indicated by the isChosenHelper property. But what about MetricKit? MetricKit is so cool. Amongst other things, it supports the MXCellularConditionMetric payload, which holds a summary of the cellular conditions while your app was running. However, this is not a real-time signal strength value. But what if I’m working for a carrier? This post is about APIs in the iOS SDK. If you’re working for a carrier, discuss your requirements with your carrier’s contact at Apple.
0
0
1.8k
Jan ’24
SecureTransport Generates SSL Continuation Message Instead of TLS Client Hello on M1
I maintain a cross-platform client side network library for persistent TCP connections targeting Win32, Darwin and FreeBSD platforms. I recently upgraded to a Mac Studio w/ M1 Max (Ventura 13.1) from a late 2015 Intel Macbook Pro (Monterey 12.6.2) and I've encountered a discrepancy between the two. For secure TCP connections my lib uses WolfSSL across all platforms but also supports use of system provided Security libraries. On Darwin platforms this is SecureTransport. Yes I am aware SecureTransport is deprecated in favor of Network. I intend to attempt to integrate with Network later but for now my architecture dictates that I use similar C-style callbacks akin to WolfSSL, OpenSSL, MBedTLS etc. On the first call to SSLHandshake the SecureTransport write callback generates 151 bytes for my TLS 1.2 connection to example.com:443 on both platforms. However, while on Intel MBP I am able to continue with the full handshake I immediately receive 0 bytes with EOF. In Wireshark on the Intel MBP the 151 bytes are observed as a TLS 1.2 client hello while on M1 it is observed as an SSL continuation message and that is the last message observed.
11
0
1.6k
Nov ’23
XCTest Bundle cannot access local network using NWConnect
I am working on a XCTest UI test automation and I want to add the ability to communicate with a test hub on our local network that controls external test equipment that is being used to create test conditions that are external to the IPAD. Currently when I run the test on the simulator running on a MAC mini it works fine and communicates with the external machine but if I run on target which is a 6th Get IPAD it receives "POSIXErrorCode(rawValue: 50): Network is down" I have tried to add permissions to the test bundle to allow this to work but nothing seems to fix it. I am a novice when it comes to IOS development in general so maybe I am missing something obvious. I thought that this https://developer.apple.com/forums/thread/668729 solution would fix my problem but adding the permissions didn't help. I am using Xcode 13.4.1, the IOS on the target is version 15.5.
17
0
2.3k
Sep ’23
WebRTC, UDP, and iOS 17
iOS 17 appears to be blocking our UDP packets for WebRTC app (native app, not safari based). The app is unable to either receive or transmit the UDP data. Works fine under IOS 16.x I'm guessing it is some form of networking privacy entitlement but can't seem to find the relevant change in IOS 17.
18
0
4.1k
Oct ’23
Crash on iOS 16 devices nw_endpoint_flow_cleanup_protocol
Hi, Our application is currently crashing in production, only for iPhone users running on iOS 16.0.x. Unfortunately, we cannot reproduce the issue, neither through direct build from Xcode or using build from app store, so it seems to happen intermittently. From third party crash analytics, it happen 35% of the time on the background, and they highlight this as the issue: Crashed: com.apple.CFNetwork.Connection EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000001545549d8 Any idea why this happens and is there anything i can do to prevent the crashes from happening again? I've also submitted this crash to Feedback Assistant with report number: FB12425295. 2023-06-07_16-46-38.7544_+0700-ef33d271e4598d57b018b15bad1ebccaabac3bee.crash
2
0
386
Jun ’23
NWTXTRecord dictionary keys are lowercased in iOS 17 beta
NWTXTRecord dictionary keys are lowercased in iOS 17, on iOS Simulator and the device. Records returned by NWBrowser in the listener block: browser.browseResultsChangedHandler = { result, changes in metadata : ["dvty": “AppName”, "txtvers": "1", "dbid": "50BFB79F"] But the actual keys are: "DvTy", "DbId". So, in iOS 17 all keys were lowercased, but not in any previous versions. And if in the app we were looking for “DvTy” key, nil is returned. The existing app simply stopped working properly in the first iOS 17 betas. Is it a bug or the app should be updated now to check for lowercased keys always? FB12309561
5
1
1k
Oct ’23
How to perform TLS Handshake with NWConnection after connected TCP to Server
Currently, I have a client by using NWConnection for a socket connection to a server in local network. My server address is ***.***.***.***:YYYY The client can connected to the server with the code below: func connect() { let connection = NWConnection(host: .init("***.***.***.***"), port: .init(integerLiteral: YYYY), using: NWParameters(tls: nil, tcp: .init())) connection.stateUpdateHandler = { state in print(state) if state == .ready { receiveData() } } connection.start(queue: .global()) } private func receiveData() { self.connection?.receive(minimumIncompleteLength: 1, maximumLength: 8192) { [weak self] (data, context, isComplete, error) in guard let self = self else { return } if let error = error { self.socketConnectionStateCallBack(.onError(connection: self, error: error)) return } if let connection = connection, connection.state == .ready && isComplete == false, let data = data, !data.isEmpty { self.socketConnectionStateCallBack(.onDataReceived(connection: self, data: data)) } } } The stateUpdateHandler callback with state == .ready and there is a receive method in that block also, so the client receive an encrypted String from the server. At this time, the client should do TSL handshake with server. (I have a certificate file) I already tried configuring TLS in NWParameters: func createTLSParameters(allowInsecure: Bool, queue: DispatchQueue) -> NWParameters { let options = NWProtocolTLS.Options() sec_protocol_options_set_verify_block(options.securityProtocolOptions, { (sec_protocol_metadata, sec_trust, sec_protocol_verify_complete) in let trust = sec_trust_copy_ref(sec_trust).takeRetainedValue() var error: CFError? if SecTrustEvaluateWithError(trust, &error) { sec_protocol_verify_complete(true) } else { if allowInsecure == true { sec_protocol_verify_complete(true) } else { sec_protocol_verify_complete(false) } } }, queue) return NWParameters(tls: options) } but received the errors: 2023-06-26 13:44:52.793596+0700 TestNWConnection[8571:237696] [boringssl] boringssl_context_handle_fatal_alert(1991) [C1:4][0x7f9807c051f0] write alert, level: fatal, description: protocol version 2023-06-26 13:44:52.793784+0700 TestNWConnection[8571:237696] [boringssl] boringssl_context_error_print(1981) [C1:4][0x7f9807c051f0] Error: 140290895852456:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/AppleInternal/Library/BuildRoots/9c39860a-c3e2-11ed-88f7-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/boringssl/ssl/tls_record.cc:242: 2023-06-26 13:44:52.794547+0700 TestNWConnection[8571:237696] [boringssl] boringssl_session_handshake_incomplete(88) [C1:4][0x7f9807c051f0] SSL library error 2023-06-26 13:44:52.794617+0700 TestNWConnection[8571:237696] [boringssl] boringssl_session_handshake_error_print(43) [C1:4][0x7f9807c051f0] Error: 140290895852456:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:/AppleInternal/Library/BuildRoots/9c39860a-c3e2-11ed-88f7-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/boringssl/ssl/tls_record.cc:242: 2023-06-26 13:44:52.794660+0700 TestNWConnection[8571:237696] [boringssl] nw_protocol_boringssl_handshake_negotiate_proceed(771) [C1:4][0x7f9807c051f0] handshake failed at state 12288: not completed waiting(-9836: bad protocol version) 2023-06-26 13:44:52.833700+0700 TestNWConnection[8571:238121] [tcp] tcp_input [C1:5] flags=[R.] seq=764001948, ack=1321044260, win=506 state=CLOSED rcv_nxt=764000508, snd_una=1321044252 So can you help me to perform TLS Handshake with NWConnection after connected TCP to Server? Many thanks!
8
0
861
Jul ’23
Client Server program using Network Framework
Hi, I am trying to build and run a sample client server using NWFramework for UDP. I have been successfully able to send and receive the packet using NWConnection and NWListner but the issue I am facing is regarding the member of NWListner which is newConnectionHandler which is used to handle receives inbound connections. But UDP is connectionless protocol and I don't want my server to receive inbound connections as in UDP the server treat each packet as independent packet without maintaining any connection or connection info of client. Please Find the refernce to the sample code below. Can it be done without newConnectionHandler or is there any way to do communication on all the Apple Family without using BSD sockets as BSD sockets are not suported on watchOS import Foundation import Network class Server { private var listener: NWListener? private let dispatchGroup = DispatchGroup() private var receivedPackets: [String] = [] func startListening() { do { let parameters = NWParameters.udp let port = NWEndpoint.Port(integerLiteral: 12345) listener = try NWListener(using: parameters, on: port) listener?.stateUpdateHandler = { state in switch state { case .ready: print("Server is ready to accept connections.") case .failed(let error): print("Server failure, error: \(error.localizedDescription)") default: break } } listener?.newConnectionHandler = { [weak self] newConnection in self?.handleNewConnection(newConnection) } listener?.start(queue: .main) //RunLoop.main.run() dispatchGroup.wait() } catch { print("Failed to start the server, error: \(error.localizedDescription)") } } private func handleNewConnection(_ connection: NWConnection) { connection.stateUpdateHandler = { state in switch state { case .ready: print("Client connected.") self.receiveData(on: connection) case .failed(let error): print("Connection failure, error: \(error.localizedDescription)") default: break } } connection.start(queue: .main) } private func receiveData(on connection: NWConnection) { connection.receiveMessage { (data, context, isComplete, error) in if let data = data, !data.isEmpty { let message = String(data: data, encoding: .utf8) print("Received message: \(message ?? "")") // Process the received message // Process the received message if let message = message { self.receivedPackets.append(message) } if self.receivedPackets.count == 50 { // All expected packets received print("Received all packets:") for packet in self.receivedPackets { print(packet) } // Close the connection after receiving all packets // connection.cancel() } else { // Continue receiving more packets self.receiveData(on: connection) } } if let error = error { print("Failed to receive data, error: \(error.localizedDescription)") } } }
7
0
664
Jul ’23