Post not yet marked as solved
Hi,
In the session it's mentioned that requests are being deduplicated when a new request with the same method, url is being sent in the same session while another one is still being performed. I never heard of it before and used to implement that manually in different apps. Is it a new feature of URLSession or should be expect this before? Does anybody know?
Best,
Karl
Post not yet marked as solved
I am writing an application that will, on the high end, have a screen-on time of > 1 hour. While the app is in use, it will need to send a heartbeat to a server via an open socket every so many seconds (usually a value between 4s and 29s), as shown below.
connection = NWConnection(host: .init(combinedAddress), port: .init(integerLiteral: port), using: .tcp)
if let ipOptions = connection.parameters.defaultProtocolStack.internetProtocol as? NWProtocolIP.Options {
ipOptions.version = .v4
}
connection.parameters.preferNoProxies = true
DispatchQueue.global(qos: .default).async {
self.heartbeatTimer = Timer.scheduledTimer(withTimeInterval: self.getHeartbeatInterval(), repeats: true, block: { _ in
self.sendHeartbeat() // eventually connection.send("heartbeat data... ", completion: {...} )
})
RunLoop.current.run()
}
During periods of less user interaction, the only data going across the network will be the heartbeat. According to this page, there's a periods of high power network activity, followed by another less energy intensive period, before the energy draw drops back down to baseline levels.
I have slight control over the heartbeat interval, and if X seconds keeps the radio at full power and Y seconds can give my users a Y-X second period of lower energy state, I can increase the time between heartbeats and take advantage of the lower power state to prevent the battery from getting hammered.
Is there a document that will provide times for the values shown in the graph, or otherwise provide guidance on how long network requests can/should be delayed for an optimized battery life?
Thank you in advance.
Note: This should all happen via Wifi, and for various reasons there's no need to take cellular modems into account.
Post not yet marked as solved
We are trying to evaluate certificate trust chain in our macOS app. We are setting the certificate chain (Root and two Intermediate CA certificates) using SecTrustSetAnchorCertificates and then calling SecTrustEvaluateWithError. The result is success.
Next time, we are calling SecTrustSetAnchorCertificates with one intermediate CA certificate missing in the certificate chain and then calling SecTrustEvaluateWithError for our server trust. The result is still success.
Next, we are calling SecTrustSetAnchorCertificates with all intermediate certificates but missing Root CA in certificate chain and then calling SecTrustEvaluateWithError for our server trust. The result is false/unsuccessful.
The first and third scenarios are expected. But how is trust evaluation successful when one of intermediate CA certificate is missing? Is macOS caching the intermediate CA certificates we have provided to SecTrustSetAnchorCertificates some other time and using it the next time when it is missing one of intermediate CA certificates since the documentation says intermediate CA certificates are looked up in different location including
Among any certificates you previously provided by calling SecTrustSetAnchorCertificates(_:_:)
but not the Root CA?
If caching is the reason, is there a way we can clear cached intermediate CA certificates so that it only uses the certificate chain I provide in most recent call to SecTrustSetAnchorCertificates? I have already tried passing nil to SecTrustSetAnchorCertificates and then passing the certificate chain in subsequent call. The result is still a success.
Note: All our Root and intermediate CA certificates are custom certificates and not available outside. We have also tried to set false in SecTrustGetNetworkFetchAllowed and result is still the same.
Post not yet marked as solved
My app is searching for few services which are running on my local network with NetServiceBrowser. As I am searching using _services._dns-sd._udp.local., I have requested and get the permission of com.apple.developer.networking.multicast (which has been discussed here ).
I have created a provisioning profile with enabling multicast entitlement according to forum guide.
But after that I still have to add Bonjour service types in Info.plist or else NetServiceBrowser throws ["NSNetServicesErrorCode": -72008, "NSNetServicesErrorDomain": 10].
<key>NSBonjourServices</key>
<array>
<string>_mydummy._tcp</string>
<string>_services._dns-sd._udp</string>
</array>
Do I still have to add each service into info.plist although I have added multicast entitlement?
Hi, I will be looking to create ping/icmp tool for macos using network framework. Can someone point me to/if there are some examples and which functions should be good to use?
Post not yet marked as solved
Hello, I am learning NWConnection and I have studied the TicTacToe app example.
I am learning by creating my own app. I am trying to create a remote mouse app (the mouse/keyboard input from iPhone) over WiFi to control my Mac.
My MacBook starts a NWListener and waits for connection. My iPhone starts a NWBrowser and I connect to a the BrowseResult. I can make a successful TCP with TLS connection with no problem thanks to the TicTacToe example.
I figured out how to move the mouse but my main goal is to get a more smooth remote mouse control.
First, I can successfully send data from my iPhone. The data I'm sending is from the DragGesture onChanged value I obtain on a View. Now everytime I drag on my View it sends Data of two Double values x and y, 16 bytes.
On the receiving end, my Macbook receives the Data and successfully parses each of the messages and then moves the mouse using Quartz Display Services API.
I implemented my own NWFramerImplementation and I can parse the message easily since I know the length of my payload data is always the same.
I get consistent smooth mouse movement when testing it on my iPad everytime, but when I use my iPhone it is horrible and there is a lot of lag/latency. I've tried using UDP on the connection and it's still the same. I turn off the data and bluetooth on my iPhone and it doesnt help
Where should I go from here?
Post not yet marked as solved
Hi
We have an app (ios) that communicates with Azure WebApp backend working on TLS1.2
Since mid May we recieve complants from our customer that the connection fails.
This happens regulary and almost of the time when using 3G/4G cellular data.
I can simulate this issue (on 4G with good connection)
The customer can use the app but after some API requests we get an exception:
NSLocalizedDescription=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://sxxxx.azurewebsites.net./api/AppRequest., NSUnderlyingError=0x2831ff810 {Error Domain=kCFErrorDomainCFNetwork Code=-1200 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9816, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9816, _NSURLErrorNWPathKey=satisfied (Path is satisfied), viable, interface: pdp_ip0, ipv4, ipv6, dns, expensive}}, _kCFStreamErrorCodeKey=-9816}
We connect directly to domain from azurewebsites.net (we don't use online custom domain).
Build with XCode 13.3
We don't use client authentication.
Any idea's what is wrong?
Regards
Peter.
Post not yet marked as solved
That's pretty much the question: we've got a tunnel provider, and I think the OS' ability to handle a captive portal situation is better than I could do, so is there a way to find out if we are in one, and if so wait for it to be handled by the user before we start doing things?
Post not yet marked as solved
Hi,
I was trying to capture ARP traffic from my iphone, I created a virtual interface using rvictl tool - rvi0. However, the packet captures on Wireshark tool for rvi0 interface do not show any ARP packets. Why is this happening?
I used the tcpdump command - tcpdump -n -t -i rvi0 -q arp, while I was able to see some request packets, the response packets were not visible, why is this happening?
Is there some other mechanism to capture ARP traffic from iphone?
Can third-party apps capture arp traffic/arp table using any Apple API?
Post not yet marked as solved
Hello!
We have a time reporting app of sorts, where one functionality we have is that users can turn on to check in and out from work via geofencing - i.e. they select a location when they want to start and end a work period. This works great.
We have had clients asking for some time to be able to use a wifi network to do the same thing. I.e. check in to work when they join a specific wifi network and checkout when they leave it. So, this is something they will want to use, and will turn on themselves if they want to use it.
I have found NWPathMonitor and this thread:
https://developer.apple.com/forums/thread/685255
that kind of asks the same thing, but it references specifying why i need it - so i did that above, hoping that someone knows whether i could accomplish this.
Thanks in advance!
Post not yet marked as solved
Hi,
I am struggling to receive multicast UDP packets on an iPad Pro (iOS 15.5) in the context of an ethernet-only lab network.
The packet reception code uses a NWConnectionGroup configured with a NWMulticastGroup, as described in https://developer.apple.com/news/?id=0oi77447.
This code works well on a Mac connected to the lab network with a USB ethernet adapter, provided the ethernet adapter interface has the highest priority among connected network interfaces.
To make it work on iOS, I have successfully added the com.apple.developer.networking.multicast to the app, following the process detailed by @eskimo in https://developer.apple.com/forums/thread/663271
However, on the iPad, the app doesn't receive any data packet on the configured connection group, although no error shows on the console.
I suspected that the issue may be related to a question of network interface selection by the receiving NWConnectionGroup, but disabling the wifi on the iPad doesn't seem to help.
Searching in the dev forums, I found this message where @meaton wrote You will want to make sure that you test this on a physical device connected to Wi-Fi to know that the Multicast feature is actually working. This makes we wonder if using the Wi-Fi network is mandatory here…
Hence my question: is there a way to receive multicast UDP packets on an ethernet network on an iPad?
Thanks.
Post not yet marked as solved
I am testing a simple TCP server/client app using the Network support on mac os x. It basically works well except when the server sends a lot of data (definition of "a lot" is that the amount of data exceeds the maximumLength value in the connection.receive call). In this case the client will receive multiple segments (each of which has less than or equal maximumLength value). For example if the maximumLength is set to 30000 and the server sends 100000 bytes, the client receive loop will get around 4 segments each of which has length <= 30000.
My question is: is there some information that the client can examine from the connection after a receive to determine that more data is available?
Post not yet marked as solved
Hi Guys, looking for tcp trace route in OSX.
In built traceroute command does not work with tcp, does any one has any solution for traceroute working with tcp?
Post not yet marked as solved
Apple's Certificate Transparency policy says that Signed Certificate Timestamps (SCTs) are accepted from TLS extension or OCSP Stapling in addition to the SCTs embedded in the certificate. If we're implementing our own Certificate Transparency enforcement in code written using URLSession, is there a way to obtain SCTs that were presented via TLS extension or OCSP Stapling?
I'm able to get the SCTs from the certificate by calling SecCertificateCopyValues with "1.3.6.1.4.1.11129.2.4.2" inside the urlSession(_:didReceive:completionHandler:) delegate function. I see that there are functions for adding TLS/OCSP SCTs to the ServerTrust, but I don't see any functions for getting them out, and I don't know if URLSession would be including those SCTs in the ServerTrust automatically anyway.
Is there any way to get these other SCTs using URLSession? Or would I have to drop down to Network Framework to do that?
Thanks for any help.
Post not yet marked as solved
We have some extensive tests which exercise UDP communication. Some of these tests fail fairly often due to the UDP packet being dropped by the kernel (or related reasons). These tests use loopback interface for communication. I have been looking to see if there's a way to pinpoint or narrow down exactly why a particular packet was dropped by the kernel. Looking at the kernel code, like here https://github.com/apple-opensource/xnu/blob/master/bsd/netinet/udp_usrreq.c#L1463 it appears that there are log message that get written out during some of this communication. However, looking at what KERNEL_DEBUG stands for, it appears that it's:
/*
* Traced only on debug kernels.
*/
#define KDBG_DEBUG(x, ...) KDBG_(_DEBUG, x, ## __VA_ARGS__, 4, 3, 2, 1, 0)
So I don't think these logs get generated in a regular release build of the OS.
Are there any other ways we can generate similar logs or any other tools that will give a clearer picture of why the packet might be drop?
Post not yet marked as solved
I have a puzzle game that is being rejected as unresponsive when todays puzzle is clicked. The app works perfectly under local versions and on test flights.
The app downloads a file via ftp each time that button is clicked. Does anyone know of an issue in the apple test environment that would prohibit ftp? I am showing a message if the app is not connected to internet.
Post not yet marked as solved
When initializing a NWConnection I noticed in NWParameters you can require or prohibit types of interfaces such as wifi, cellular, or wiredEthernet.
I want to explicitly use awdl0 and not en0. Both are wifi type interfaces. I noticed sometimes my device uses en0 and other times uses awdl0.
Post not yet marked as solved
Howdy from Germany.
I try to add a local httpServer with swift-http-server (https://github.com/bjtj/swift-http-server).
import SwiftUI
import SwiftHttpServer
@main
struct MyApp: App {
init() {
print("init")
let server = HttpServer(port: 9090)
class GetHandler: HttpRequestHandler {
var dumpBody: Bool = true
func onHeaderCompleted(header: HttpHeader, request: HttpRequest, response: HttpResponse) throws {
}
func onBodyCompleted(body: Data?, request: HttpRequest, response: HttpResponse) throws {
response.status = .ok
response.data = "Hello".data(using: .utf8)
}
}
do {
try server.route(pattern: "/", handler: GetHandler())
} catch let serverError {
print(serverError)
}
let queue = DispatchQueue.global(qos: .default)
queue.async {
do {
try server.run()
} catch let error {
print(error)
}
}
}
var body: some Scene {
WindowGroup {
ContentView() // Standard ContentView
}
}
}
When I try to add the local network rights on macOS (Montery 12.4 21F79) in the Playgrounds.app (Version 4.1 (1676.15)) it crashes everytime I hit the (+) button.
On iPad (Air 4th gen) with latest ipadOS it works fine. I can add the network rights and can serve the little hello page, by entering :9090/
As mentioned on macOS not possible. Of couse if I reload the Playgrounds project on the Mac, the local network rights are now included, but still on the mac the "Hello" page is not served.
Any hints/tips how to solve this problem? Need I to add more rights? Do I have to report the crash somewhere? I have the crashlog.
Thanks in advance.
Alex
PS: Background: I try to write a Playgrounds App which generates some output on a webpage, which then is served via the in-app webserver, which then is integrated on Obs via web page plugin...
Post not yet marked as solved
Hello. This week we had two users that have tried to using our app for the first time, but, saddly, for some reason they are not reaching our API. The devices are an iPhone 7 and 12, both with iOS 15.5. We already tried to get some information about a possible block on our Cloud Flare, but there aren't. They both can only reach our api when trying via web browser, but when trying with our app, they cannot reach our servers. We already tried reinstalling the app and rebooting both devices.
Please, any thoughts?
Hi,
I wanted to try using the new NWBrowser available in iOS 13 to replace my old Bonjour browsing code(NetServiceBrowser), problem is I'm unabe to get all IPv6 Addresses(except link local address) of the service I'm looking for.
In my environment, when I checked with ifconfig command, there are three IPv6 addresses.
fe80::c092:a0ff:fe51:3c8
fd1c:efcd:7e66:0:c092:a0ff:fe51:3c8
fd1c:efcd:7e66:0:68d:6b27:81e2:7511
Using NWBrowser and NWConnection, I ended up getting #1 address but I couldn't get #2, #3 addresses.
Here is my code.
let bonjour = NWBrowser.Descriptor.bonjourWithTXTRecord(type: serviceType, domain: searchDomain)
let params = NWParameters.init()
self.nwBrowser = NWBrowser(for: bonjour, using: params)
self.nwBrowser?.browseResultsChangedHandler = { [weak self] results, changes in
guard let self = self else { return }
for change in changes {
if case .added(let result) = change {
let connection = NWConnection(to: result.endpoint, using: .udp)
connection.stateUpdateHandler = { [weak self] state in
switch state {
case .ready:
if let remoteEndpoint= connection.currentPath?.remoteEndpoint,
case .hostPort(let host, let port) = innerEndpoint {
// here I can get #1 address from host
// but, I couldn't get #2, #3 addresses
}
}
}
connection.start(queue: .main)
}
}
}
self.nwBrowser?.start(queue: .main)
Using NetServiceBrowser and netServiceDidResolveAddress(), I can get All IP addresses(#1, #2, #3)
Here is my code.
let netServiceBrowser = NetServiceBrowser()
netServiceBrowser.delegate = self
netServiceBrowser.searchForServices(ofType: serviceType, inDomain: searchDomain)
func netServiceBrowser(_ browser: NetServiceBrowser, didFind service: NetService, moreComing: Bool) {
service.delegate = self
service.resolve(withTimeout: resolutionTimeoutSeconds)
}
func netServiceDidResolveAddress(_ service: NetService) {
// service.addresses is [Data], I can get all addresses I want.
}
I wonder if getting only Link Local Address through NWConnection is the intended behavior.
Or is there a way to get all address using NWBrowser and NWConnection?