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 Simcard Status
In order to get more accurate compass data it seems that iOS devices with a simcard installed can provide better results. To distinguish between data delivered I would like to retrieve a status telling me if there is a simcard available and connected to the mobile network or not. All recommendations are pointing to the deprecated CoreTelephony functions which are obsolete since I am working with iOS17 devices. Is there a way to check if the device uses a simcard or not?
1
0
975
Mar ’24
wifi & proxy settings have disappeared from all iOS phone simulators!
Seems bizarre but since updating to Sonoma (14.2), I've actually lost menu items in the iOS phone simulators. Basically there is no longer any Settings->wifi item in the simulators' menu at all, so I can't do what I've always done & set a manual proxy (in order to use Charles proxy). I've been doing this for years & we generally use about 4 or 5 simulators for testing with Xcode, and now suddenly there's no ability to set a manual proxy on any of them - they have all lost these menu items. Does anyone know what has gone one & how I fix this, please !!!! I can't find info about this via the usual googling. If it makes any difference I'm using Xcode 15.2, 16" MacBook 2019 with intel chipset.
0
0
523
Mar ’24
Inquiry Regarding NEHotspotNetwork fetchCurrent Method
I am reaching out regarding the usage of the fetchCurrent method within the NEHotspotNetwork framework. According to the documentation provided at [https://developer.apple.com/documentation/networkextension/nehotspotnetwork/3666511-fetchcurrent], it is mentioned that in order to utilize this method, the application needs to meet all four of the following conditions: The app is using the Core Location API and has the user’s authorization to access precise location. The app used the NEHotspotConfiguration API to configure the current Wi-Fi network. The app has active VPN configurations installed. The app has an active NEDNSSettingsManager configuration installed. However, upon reviewing the comments in the code for the fetchCurrent method, it states: "This method returns SSID, BSSID, and security type of the current Wi-Fi network when the requesting application meets one of the following 4 requirements -." Could you please clarify whether it is necessary to fulfill all four conditions or if meeting just one of the four requirements is sufficient to use the fetchCurrent method?
1
0
391
Mar ’24
Advanced UDP with Network.framework
I finally found a time to experiment with Network.framework and I find the experience very pleasant. The API looks well thought out and is a pleasure to work with. My app (on the App Store for around 13 years) uses UDP networking to create a mesh between multiple devices where each device acts as a server and client at the same time. It does that by creating one UDP socket on each device bound to a *:<port> and then uses that socket to sendmsg to other peers. That way all peers can communicate with each other using their well known <port>. This all works great and fine. To test the performance and verify the functionality I have multiple XCTestCase scenarios where I create multiple peers and simulate various communications and verify their correctness. Within the XCTestCase process that means creating multiple underlying sockets and then bind them to multiple local random <port>s. Works great. Now I'm trying to port this functionality to Network.framework. Let's assume two peers for now. Code simplified. Prepare NWParameter instances for both peers, plain UDP for now. // NOTE: params for peer 1 let p1 = NWParameters(dtls: nil, udp: .init()) p1.requiredLocalEndpoint = .hostPort(host: "0.0.0.0", port: 2222) p1.allowLocalEndpointReuse = true // NOTE: params for peer 2 let p2 = NWParameters(dtls: nil, udp: .init()) p2.requiredLocalEndpoint = .hostPort(host: "0.0.0.0", port: 3333) p2.allowLocalEndpointReuse = true Create NWListeners for each peer. // NOTE: listener for peer 1 - callbacks omitted for brevity let s1 = try NWListener(using: parameters) s1.start(queue: DispatchQueue.main) // NOTE: listener for peer 2 - callbacks omitted for brevity let s2 = try NWListener(using: parameters) s2.start(queue: DispatchQueue.main) The listeners start correctly and I can verify that I have two UDP ports open on my machine and bound to port 2222 and 3333. I can use netcat -u to send UDP packets to them and correctly see the appropriate NWConnection objects being created and all callbacks invoked. So far so good. Now in that XCTestCase, I want to exchange a packets between peer1 and peer2. So I will create appropriate NWConnection and send data. // NOTE: connection to port 3333 from port 2222 let c1 = NWConnection(host: "127.0.0.1", port: 3333, using: p1) c2.start(queue: DispatchQueue.main) // NOTE: wait for the c1 state .ready c2.send(content: ..., completion: ...) And now comes the problem. The connection transitions to .preparing state, with correct parameters, and then to .waiting state with Error 48. [L1 ready, local endpoint: <NULL>, parameters: udp, local: 0.0.0.0:2222, definite, attribution: developer, server, port: 3333, path satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, uses wifi, service: <NULL>] [L2 ready, local endpoint: <NULL>, parameters: udp, local: 0.0.0.0:3333, definite, attribution: developer, server, port: 2222, path satisfied (Path is satisfied), interface: en0[802.11], ipv4, dns, uses wifi, service: <NULL>] nw_socket_connect [C1:1] connectx(6 (guarded), [srcif=0, srcaddr=0.0.0.0:2222, dstaddr=127.0.0.1:3333], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [48: Address already in use] nw_socket_connect [C1:1] connectx failed (fd 6) [48: Address already in use] nw_socket_connect connectx failed [48: Address already in use] state: preparing connection: [C1 127.0.0.1:2222 udp, local: 0.0.0.0:2222, attribution: developer, path satisfied (Path is satisfied), interface: lo0] state: waiting(POSIXErrorCode(rawValue: 48): Address already in use) connection: [C1 127.0.0.1:3333 udp, local: 0.0.0.0:2222, attribution: developer, path satisfied (Path is satisfied), interface: lo0] I believe this happens because the connection c1 essentially tries to create under the hood a new socket or something instead of reusing the one prepared for s1. I can make the c1 work if I create the NWConnection without binding to the same localEndpoint as the listener s1. But in that case the packets sent via c1 use random outgoing port. What am I missing to make this scenario work in Network.framework ? P.S. I was able to make it work using the following trick: bind the s1 NWListener local endpoint to ::2222 (IPv6) connect the c1 NWConnection to 127.0.0.1:3333 (IPv4) That way packets on the wire are sent/received correctly. I would believe that this is a bug in the Network.framework. I can open a DTS if more information is needed.
8
0
1.8k
Mar ’24
Frequent sleep and wake events in the Tunnel Provider
Hi! We are investigating the power consumption of our VPN app on iOS. We noticed that while the VPN tunnel is started, we frequently experience sleep and wake events. Depending on the device it varies somewhere between 60 - 600 times during an overnight test where the device is just laying around and doing absolutely nothing. I looked into the system logs, and the wake reason is always this one: 2024-03-01 03:09:00.836588+0200 0x35e96 Default 0x0 50 7 wifid: (WiFiPolicy) [com.apple.WiFiPolicy:] System wake reason: SMC.OutboxNotEmpty smc.70070000 baseband I googled what OutboxNotEmpty means, but I only found several macOS-related topics. Interestingly, when I leave the same phone without a VPN running, I don't see the above log even once during an overnight test. I also tested a different VPN app and saw the above log in the system logs. This makes me think this is either some iOS feature I don't understand or some bug that causes frequent wakeups. I'd appreciate any feedback if this is a known issue or if we need to do something differently within our tunnel implementation.
4
1
809
Mar ’24
[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.4k
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
684
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
1.1k
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
1k
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.8k
Mar ’24