Networking

RSS for tag

Explore the networking protocols and technologies used by the device to connect to Wi-Fi networks, Bluetooth devices, and cellular data services.

Networking Documentation

Post

Replies

Boosts

Views

Activity

[iOS 17.4, XCode 15.3] Previously working NWConnection for peer-to-peer connection now permanently stuck on "Preparing"
After updating my devices to iOS/iPadOS 17.4, and XCode to 15.3, Network framework peer-to-peer connections have stopped working entirely. The system was working fine before and the code has not been changed. On the client side (NWBrowser) the server (NWListener) can be seen, but upon attempting to establish a connection the client-side NWConnection.State gets permanently stuck at .preparing. NWConnection.stateUpdateHandler doesn't enter any other state. It doesn't seem as though it's taking a long time to prepare; it's just stuck. This situation occurs across multiple connection modes (wired, common wifi, separate wifi). Additional information I didn't participate in the 17.4 beta and RC The code in "Creating a custom peer-to-peer protocol" works--this code forms the basis of my code
2
0
1.3k
Mar ’24
Bluetooth: prohibiting or detecting unwanted pairing request alert on connect
When calling CBCentralManager's connectPeripheral:options: with some Bluetooth devices I'm getting the "Bluetooth Pairing Request" alert on iOS and a similar "Connection Request from:" alert on macOS. Is there a way to determine upfront if the alert is going to be presented or not? Alternatively is there a way to prohibit presenting this alert (in which case the connect request could fail, which is totally fine)? I tried specifying these options: var manager: CBCentralManager ... manager.connect( peripheral, options: [ CBConnectPeripheralOptionNotifyOnConnectionKey: false, CBConnectPeripheralOptionNotifyOnDisconnectionKey: false, CBConnectPeripheralOptionNotifyOnNotificationKey: false ] ) but those didn't help (and by the doc they shouldn't help as they relate to the use case of app running in background, which is not applicable in my case – my app runs and calls connect when it is in foreground, the unwanted alert is displayed immediately).
2
0
617
Mar ’24
List available WiFi networks in Sonoma
Hi, I am trying to get a list of available WiFi networks for a sandboxed macOS app: CWInterface *wifi = [[CWWiFiClient sharedWiFiClient] interface]; NSError *err; NSSet *scanset = [wifi scanForNetworksWithSSID:nil error:&err]; // scanset is always empty (but not nil), no error is writting to "err" With macOS Sonoma the code always returns an empty list (with older macOS version it works fine). I already added Location permission (as described here: https://developer.apple.com/forums/thread/732431). Getting the currently connected WiFi SSID (using [CWInterface interface].ssid), as well as connecting to a WiFi network works. How can I get a list of available WiFi SSIDs in macOS Sonoma? Regards,
2
0
918
Mar ’24
Create a PDF-File of a view with correct papersize
Hello together, does anyone know how I can scale a view to a given document size (e.g. A4: 210/297 mm) without scaling the view itself? With enclosed code I can create the pdf-document, but the paperize is not the intended size. It is too big. Variation this line of code var mediaBox = CGRect(origin: .zero, size: CGSize(width: size.width, height: size.height)) into var mediaBox = CGRect(origin: .zero, size: CGSize(width: 595, height: 842) does not scale the view (it just shows a part of it at the correct papersize). So what do I have to do to scale the rendered view to the proper size? Enclosed a very simple code snipped to see th strange behavior. Thx, best regards Peter import SwiftUI struct ContentView: View { var body: some View { ZStack { Rectangle() .frame(width: 2100, height: 2910) .foregroundColor(.red) Rectangle() .frame(width: 2100/2, height: 2910/3) .foregroundColor(.blue) Text("Hello, world!") } .padding() .onAppear(perform: { generatePDF() }) } // generate pdf from given view @MainActor func generatePDF() -> URL { // Select UI View to render as pdf let image = ImageRenderer(content: ContentView()) let url = URL.documentsDirectory.appending(path: "generatedPDF.pdf") image.render{ size, context in var mediaBox = CGRect(origin: .zero, size: CGSize(width: size.width, height: size.height)) guard let consumer = CGDataConsumer(url: url as CFURL), let pdfContext = CGContext(consumer: consumer, mediaBox: &mediaBox, nil) else { return } pdfContext.beginPDFPage(nil) pdfContext.translateBy(x: mediaBox.size.width / 2 - size.width / 2, y: mediaBox.size.height / 2 - size.height / 2) context(pdfContext) pdfContext.endPDFPage() pdfContext.closePDF() } print("Saving PDF to \(url.path())") return url } } #Preview { ContentView() } ![]("https://developer.apple.com/forums/content/attachment/67b11ec8-af9e-4ab7-a0a5-0c020b7a45d4" "title=generatedPDF (without scaling).jpg;width=2652;height=2526") ![]("https://developer.apple.com/forums/content/attachment/b2c24a25-3805-4664-8adb-dcb81c3e96c4" "title=generatedPDF (with scaling).jpg;width=2132;height=1510")
1
0
843
Mar ’24
Excute "airport -s" failed on mac os 14.4
It was possible to excute: sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s on previous mac os version to get all SSID list. But now on mac os 14.4 it returns like: WARNING: The airport command line tool is deprecated and will be removed in a future release. For diagnosing Wi-Fi related issues, use the Wireless Diagnostics app or wdutil command line tool. Is there any other way to list all SSIDs? It's important to me since my code depends on this feature. P.S. Seems other airport command like "airport -I" didn't work too. Is there any other tool could replace airport?
3
2
3.4k
Mar ’24
NWConnection vs. nw_connection_t
I have ported my code from BSD sockets over to Network.framework, and while blocking issues remain (https://forums.developer.apple.com/forums/thread/747815) and while I can not yet properly instrument my code because os_signpost does not seem to work on XCTestCases profiled directly from Xcode (https://forums.developer.apple.com/forums/thread/748059) I do already have some initial observations. Perf test case of sending full (~1280 bytes) UDP datagrams back and forth over lo0 indicates that BSD sockets code can achieve 20% higher throughput (in packets per second) than Network.framework based code. That is not what I expected, and I will continue investigating but for the moment I have one question I did not find answer to. Will using C based Network.framework API instead of Swift based one bring performance gains? For example, nw_connection_t provides an interface to send non-contiguous segments of dispatch_data_t without copying, whereas NWConnection only deals with contiguous Data. Thanks for any insights.
2
0
704
Mar ’24
NWParemeters.requiredLocalEndpoint is ignored in VisionOS
I have a an application that incorporates a RTCP client to communicate with a local networked device. The device's RTCP implementation requires that the local RTCP port be 6970 even for the initial outbound connection. I have an implementation that is working just fine on macOS and iOS, but I when I port this to visionOS, I see that the local connection is ignoring my .requiredLocalEndpoint specification and choosing a random port (I can see this is happening in Wireshark via the VisionOS simulator.) let remoteRtcpEndpoint = NWEndpoint.hostPort(host: NWEndpoint.Host(remoteRTCPAddress), port: NWEndpoint.Port(rawValue: remoteRTCPPort)!) let rtcpParameters = NWParameters.udp let localEndpoint = NWEndpoint.hostPort(host: NWEndpoint.Host("0.0.0.0"), port: NWEndpoint.Port(rawValue: localRTPPort)!) Self.logger.info("Starting rtcp with local port \(localRTPPort), remote address \(remoteRTCPAddress), endpoint \(String(describing: localEndpoint))") rtcpParameters.requiredLocalEndpoint = localEndpoint rtcpParameters.allowLocalEndpointReuse = true remoteRtcpConnection = NWConnection(to: remoteRtcpEndpoint, using: rtcpParameters) remoteRtcpConnection.start(queue: .global()) And here's the code that sends the command. remoteRtcpConnection.send(content: RtcpPacket.vdly(delayMs: HUGE_FIXED_VDLY_MS).packet(), completion: .contentProcessed({ error in if let error = error { Self.logger.warning("Error sending VDLY packet \(error)") continuation.resume(throwing: error) } else { Self.logger.debug("VDLY Sent \(self.HUGE_FIXED_VDLY_MS)") continuation.resume(returning: ()) } })) If this is a known limitation of the Network framework, should I revert to BSD sockets or something? How can I work around this? Additionally, I don't have a VisionOS device, so I am using the simulator, could this be a problem with the simulator's network bridge?
4
0
581
Mar ’24
Trouble with inbound multicast on home network
I am using UDP multicast to send messages to an embedded host (Raspberry Pi) in my home network but I am running into issues receiving multicast traffic on Ventura 13.4. I have a simple Python receiver/sender script: receiver.py (with from_nic_ip set as the local address related to the port that I want to bind to, multicast addr: 224.0.0.0, multicast port: 42073) def receive_loop(from_nic_ip, multicast_group_ip, multicast_port): receiver = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM,\ proto=socket.IPPROTO_UDP, fileno=None) multicast_group = (multicast_group_ip, multicast_port) receiver.bind(multicast_group) if from_nic_ip == '0.0.0.0': mreq = struct.pack("=4sl", socket.inet_aton(multicast_group_ip), socket.INADDR_ANY) else: mreq = struct.pack("=4s4s",\ socket.inet_aton(multicast_group_ip), socket.inet_aton(from_nic_ip)) receiver.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) while True: buf, _ = receiver.recvfrom(BUFSIZE) msg = buf.decode() print(msg) reciver.close() sender.py def send_loop(host_ip_addr, multicast_group_ip, multicast_port): sender = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM,\ proto=socket.IPPROTO_UDP, fileno=None) multicast_group = (multicast_group_ip, multicast_port) sender.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 1) sender.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF,\ socket.inet_aton(host_ip_addr)) while True: print("Sending data!") sender.sendto("test".encode(), multicast_group) time.sleep(1) sender.close() If I run macOS as a sender and the Raspberry Pi as the receiver, I get the expected output: "test" printed continuously. If I reverse the roles, I see no "test" output. I have verified that the script works as a sender/receiver by duplicating the test on a Linux desktop and I see that the two nodes can communicate with each other as both a sender or receiver.
1
0
420
Mar ’24
Issues with Multipeer Connectivity on iPadOS 17.4
Hello! We have an app that runs on two iPads, in two different modes, that communicate with one another using Apple's Multipeer Connectivity APIs. Last week, after upgrading to iPadOS 17.4 we have had MANY customer reports of erratic connectivity, only on iPadOS 17.4. The iPads connect for 30 seconds to a minute, disconnect, reconnect for a short time again, and repeat. Most of our customers are school districts who likely employee an MDM and we are working on verification of that in order to reproduce the issue in-house. Were there changes to the MPC framework in iPadOS 17.4 that could be causing sessions to be dropped? Are you aware of any interaction with device management software that could cause this?
1
0
983
Mar ’24
EndpointSecurity and network events
Hello, I know that EndpointSecurity doesn't support network events, save for some events related to Unix pipes. In WWDC 2020 #10159 Apple says that: Those of you who have already worked with the EndpointSecurity framework have likely noticed that we do not provide events related to networking operations. This is intentional as these are better covered by the NetworkExtension framework. Could you please give me a short and high-level hint how I can use NetworkExtension to provide connect, disconnect events to a monitoring app, that tries to log those events in a database? I would like to receive the remote IP and remote port + local port. From what I've researched, In NetworkExtension documentation it's stated that it's possible to create a "content filter", which would probably be a good source of information; the problem is that because of the privacy requirements, the "content filter" can't send back any information about user data, because it's separated in a restrictive sandbox. So I'm not sure the "content filter" would even be possible to be used as a source of network events. Other types of categories inside NetworkExtension doesn't seem to be a good match for my use case. Is it possible to use NetworkExtension to get information about network events (connect/disconnect), like EndpointSecurity does for i.e. processes (process start/process end)?
3
0
869
Mar ’24
Very old CoreWLAN bug?
With the deprecation of the airport binary in macOS 14.4 I am re-writing my own network tool to directly use CoreWLAN. In doing this and testing and comparing to previous results from the Apple airport binary under various versions of macOS I believe CoreWLAN has a 'bug' which as a result was exhibited in the Apple airport binary and equally my own code. As detailed below. This applies to the release version of macOS 14.4 (23E214) macOS Sonoma 14.3.1 and previous versions of macOS going back many, many years have included an official Apple binary at the following location. /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport Whilst this is now officially deprecated in macOS 14.4 it is obvious that this tool will have itself been utilising the official Apple framework CoreWLAN. As part of the process of re-writing my own tool which formerly used the above Apple binary, I have re-written my tool to directly utilise CoreWLAN myself via the Objc interface. In doing this I have been able to in my own tool reproduce an incorrect behaviour formerly exhibited by the airport binary and still exhibited with my own tool directly utilising CoreWLAN. It therefore appears the issue is in CoreWLAN and not the now deprecated airport binary. Using the airport binary in macOS 14.3.1 (the last working version) I get a result like the following. SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group) vodafone20645C -89 6 Y -- RSN(PSK/AES/AES) vodafone20645C -89 60 Y -- RSN(PSK/AES/AES) You can see the column for CC which stands for country code is empty and hence shows ‘--‘. This field should indicate the country the WiFi access point is configured to support. (This affects the available choices of WiFi channels, transmitter strength and other aspects in order to render the access point LEGAL to use in various countries.) Using my own code under the same version of macOS written to directly call CoreWLAN and obtain the same information I get the same results i.e. CoreWLAN does not return any country code information. My code under both macOS 14.3.1 and 14.4 returns the same results i.e. no country code. As a comparison here is the output from the airport binary included in macOS 12.7.4 (21H1123) SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group) vodafone20645C -89 6 Y -- RSN(PSK/AES/AES) vodafone20645C -89 60 Y -- RSN(PSK/AES/AES) As you can see it is identical confirming this bug has existed for a long time. To show this however DID NOT USE TO EXIST here is the result from a much older macOS X Yosemite 10.10.5 (14F2511) SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group) VM2833142 cc:58:30:07:32:48 -88 108 Y NL WPA2(PSK/AES/AES) EE WiFi 62:e5:32:e3:ab:35 -61 11 Y GB NONE EV home 78:85:f4:42:02:58 -57 11 Y CN WPA2(PSK/AES/AES) SKYGW3RD 3c:45:7a:fe:6b:0a -63 11 Y -- WPA2(PSK/AES/AES) BT-6FCW7K c4:e5:32:e3:ab:34 -61 11 Y GB WPA2(PSK/AES/AES) As you can see in this case it is listing access points that are set to respectively, Netherlands, Great Britain, China, ‘Unknown’, and Great Britain. (As an aside and not part of this bug I am reporting, CoreWLAN has not reported the BSSID aka MAC address for some time either.) Note: The countryCode field is still defined in CoreWLAN as retrieving it does not generate an error unlike picking a non-existent field name. See also - https://developer.apple.com/documentation/corewlan/cwinterface/countrycode()
3
0
813
Mar ’24
Troubleshooting Peer-to-Peer Connection Failure between iOS Apps Using NWListener, NWConnection, and STUN
I am currently developing two iOS applications that require peer-to-peer connectivity. To facilitate this, I've implemented NWListener and NWConnection in both apps for network communication. To determine each device's public IP address and port—necessary for establishing a connection over the internet through my mobile operator's Carrier-Grade NAT (CGNAT)—I'm using a STUN server. Despite successfully retrieving the external IP addresses and ports for both devices, I am unable to establish a peer-to-peer connection between them. My current setup involves initiating a connection using the public addresses and ports discovered through the STUN server response. However, all attempts to connect the devices directly have been unsuccessful. I am seeking guidance on whether there are additional considerations or specific configurations needed when using NWListener, NWConnection, and a STUN server to establish a direct connection between devices in a CGNAT environment. Is there a particular step or network configuration I might be missing to successfully connect both iOS devices to each other using their external network details?
1
0
736
Mar ’24
How to add a CBMutableDescriptor
Hello, whenever I want to add a CBMutableDescriptor, either with CBMutableDescriptor(type: CBUUID(string: "2901"), value: nil) or using the defined string CBUUIDCharacteristicUserDescriptionString: I get the following error message: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Expecting NSData value type for Format descriptor' What am I doing wrong here? Thanks
1
0
539
Mar ’24