Post not yet marked as solved
Hallo everyone! I'm working on a WatchOS app uploading files to servers using URLSession. It works fine when the paired phone is there. However, if the paired iphone is not reachable (e.g. switch-off, out-of-reach, etc.), AND the watch is connected to Wifi, the URLSession fails to post messages, and times out.According to Apple documentation, WatchOS Wifi should work stand-alone.https://developer.apple.com/documentation/watchkit/keeping_your_watchos_app_s_content_up_to_date/testing_watchos_networking"Connecting to a known network. If the watch cannot connect to a paired iPhone, but it can connect to a known WiFi network (a network that the user has previously logged into with their phone), then the request is sent using the WiFi network. When connected to a known network, the control center shows the WiFi network in the upper left corner."I am struggling with this. Does anyone have successful experience, using URLSession and making WatchOS Wifi only connections in the App? Thanks a lot in advance!Zhaorui
I have an iOS app and a MacOS app in which I want to display to the user it's device's local IP.If there is more than one IP, I would dispaly one of them, not matter which one.This is the code I'm using:func getIFAddresses() -> String {
//var addresses = [String]()
var address = "N/A"
deviceLocalIp = "N/A"
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer?
guard getifaddrs(&ifaddr) == 0 else { return address }
guard let firstAddr = ifaddr else { return address }
// For each interface ...
for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
let flags = Int32(ptr.pointee.ifa_flags)
var addr = ptr.pointee.ifa_addr.pointee
// Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) {
let interfaceName = String.init(cString: &ptr.pointee.ifa_name.pointee)
//DDLogInfo("interfaceName:\(interfaceName)")
// Convert interface address to a human readable string:
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
if (getnameinfo(&addr, socklen_t(addr.sa_len), &hostname, socklen_t(hostname.count),
nil, socklen_t(0), NI_NUMERICHOST) == 0) {
if interfaceName == "en0" {
deviceLocalIp = String(cString: hostname)
address = deviceLocalIp
break
}
//if we don't have address from en0 - try get it from another interface
//(but prefer from en0)
if address == "N/A" && (interfaceName == "en0" || interfaceName == "en1" || interfaceName == "en2" || interfaceName == "pdp_ip" || interfaceName == "ap1") {
deviceLocalIp = String(cString: hostname)
address = deviceLocalIp
}
}
}
}
}
freeifaddrs(ifaddr)
return address
}
}For IPv4 it seems to work well.For IPv6 (via Mac's Internet Sharing), I'm getting an IPv6 address, but it's not the address I'm expecting to connect -at the Network I see that my device is connected and has the IP address X and the result I'm getting with this code is address Y.P.S -For debugging, I printed all the IPs, not just the first, and still didn't get the correct one..
Post not yet marked as solved
I'm investigating some reported connectivity issues from users of our iOS app. The app is failing to load/refresh data for multiple minutes at a time, despite other apps, Safari, etc. working fine. We are investigating this at various layers in the pipeline (i.e. server-side, network), but I'm taking a look at what we know or can find out on the client.I'm sure a lot of these kinds of issues get posted which end up being caused by transient network issues but I have a few specific questions about how I can find out more, and some questions around the behaviour of URLSession, so hopefully there are some people qualified to answer (BatEskimo-signal activated).
packet trace or gtfo 🙂
Unfortunately we've been unable to get a network/packet trace as this requires reproducing the issue locally which we haven't been able to do.Device logs show what look like typical timeout errors, occurring 60 seconds after initiating the requests:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x280764ae0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, NSErrorFailingURLStringKey=https://REDACTED, NSErrorFailingURLKey=https://REDACTED, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.})
The app is trying to send multiple requests over the minutes things are not working, and they are all failing with the same timeout error after 60 seconds. We've had users give up after 5 minutes because nothing is working. This is despite them having a good cellular or wifi connection and with other apps and Safari working. The users who have reported this so far are on iOS 12.We are using a single URLSession for all our requests, created when the app starts. It's pretty vanilla: the config is a URLSessionConfiguration.default but with a custom User-Agent to override the default one, added via httpAdditionalHeaders. All our requests hit the same https hostname, and they are all POSTs.Now the interesting part is that we have a separate health check request we send occasionally which sends a POST to exactly the same end point as normal requests, and we are seeing this succeed during the periods when regular requests are timing out. One difference with the ping check is that we use a different URLSession instance on the client. This URLSession is also created on startup, and uses the same configuration. The only difference is a delegate that we use to do some cert pinning and report any certificate mismatch from what we expect.We do have DNS load balancing on our end point, so different connections can end up hitting a different IP.So there are a few initial thoughts and questions I have:The failing requests could be going to a different IP than the successful health check ones, and a specific server could be bad in some way. Is there a way to log the resolved IP address that a particular URLSession task used, at the point of receiving the error? Googling and looking in the docs doesn't show an obvious way to get this information. I imagine since URLSession can maintain a pool of connections to the same host, and there can be redirects during a request, that this is difficult to expose "nicely" via the API. We can obviously do this with local profiling but we would like to add telemetry to gather this data in the wild if possible.Is it possible the "bad" URLSession is reusing a stale/dead persistent (keep-alive) connection, and everything on that socket is just timing out? What is the behaviour of connection reuse in these situations and under what circumstances will URLSession open a new connection? How long will it reuse a connection for? Will it continue reusing a connection even when requests are failing with timeout errors, even for multiple minutes?Is there a way to log exactly where in the lifetime of the request the URLSession task got to before it timed out? i.e. did it even resolve DNS? Did it connect at all? Did it finish the TLS handshake? Did it send headers? Did it receive anything at all? There is the NSURLSessionTaskMetrics API but it doesn't look like there's an easy way to correlate an event from urlSession(_ session: URLSession, task: URLSessionTask, didFinishCollecting metrics: URLSessionTaskMetrics) to a particular data task / request, so we'd have to log everything (maybe checking if response is null to detect an incomplete load) and correlate later.Some docs (e.g. "Technical Q&A QA1941" which I won't link because this post will be put in a moderator queue) talk about some retry behaviour in URLSession for idempotent (e.g. GET) vs. non-idempotent (e.g. POST) requests, at least for "The network connection was lost" errors. Is there a similar or related behaviour for timeouts, or when a connection looks dead? If this is some transient network issue, would GET requests behave better in such situations when stuff is timing out? There are reasons we are using POST but it would be interesting to know more about how differently idempotent requests are treatedThanks in advance
Post not yet marked as solved
My sandboxed Mac VoIP application is trying to set a QoS DiffServ DSCP value to mark RTP traffic transmitting voice. It is doing that via a third-party open source library. Specifically, the setsockopt() function is called with the value NET_SERVICE_TYPE_VO in its fourth argument:status = setsockopt(sock, SOL_SOCKET, SO_NET_SERVICE_TYPE, (void *)&val, sizeof(val));The function returns success.However, when I'm tcpdumping this traffic, I see ToS value 0x0. This is happening on macOS 10.14 Mojave. The same binary running on macOS 10.10 produces the expected result: the ToS value provided by tcpdump shows the non-zero value 0xc0.Am I missing something or should I creae a bug report?
Post not yet marked as solved
I've looked into a good number of articles on how to do a multipart/form-data POST on iOS, but none really explain what to do if there were normal parameters as well as the file upload.I have used the multipart/form-data POST on iOS & I had written the following code and it is uploading data but not image data - (void)postWithImage:(NSDictionary *)dictionary{ NSString *urlString = [NSString stringWithFormat:@"YourHostString"]; NSURL *url = [NSURL URLWithString:urlString]; NSString *boundary = @"----1010101010"; // define content type and add Body Boundry NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; NSEnumerator *enumerator = [dictionary keyEnumerator]; NSString *key; NSString *value; NSString *content_disposition; while ((key = (NSString *)[enumerator nextObject])) { if ([key isEqualToString:@"file"]) { value = (NSString *)[dictionary objectForKey:key]; NSData *postData = UIImageJPEGRepresentation([UIImage imageNamed:value], 1.0); [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\";\r\nfilename=\"screen.png\"\r\n\r\n",value] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:postData]; } else { value = (NSString *)[dictionary objectForKey:key]; content_disposition = [NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key]; [body appendData:[content_disposition dataUsingEncoding:NSUTF8StringEncoding]]; NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:value options:NSJSONWritingPrettyPrinted error:&error]; [body appendData:jsonData]; //[body appendData:[value dataUsingEncoding:NSUTF8StringEncoding]]; } [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; } //Close the request body with Boundry [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:body]; [request addValue:[NSString stringWithFormat:@"%d", body.length] forHTTPHeaderField: @"Content-Length"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"%@", returnString);}Can anyone please help me to get why image data is not uploading
How do I do this using a programmatically set static IP address for the host iPhone.
Post not yet marked as solved
Hi eskimo :I'm a developer who browse Apple Developer Forums.I want to ask you the question about captive portal.Now I use the WiFidog,a captive portal suite,to implement this function.I use some iPhone such as iPhone6,6s,SE,that could popup authentication page quickly(For example like attachment).However,I use iPhone7 and iPhone X that popup authentication page very slowly,which takes about 50 seconds.I guess there is the problem for Evaluate and hotspothelper.But I don't know how to solve the problem if I couldn't change the iPhone which is Customer-owned.Looking forward to receiving your reply.
Post not yet marked as solved
Hello everyone,I'm currently creating a Swift Framework to add TCP capabilities to a C++ application.And I have issues I don't meet when I test my Swift code out of a framework.To be brief: I never receive failed state updates, the stateUpdateHandler is never called with a failed State or with a cancelled State. This happens whatever the way the connection is cut, either when I kill the client application or when I call cancel() client side. I receive waiting and ready states properly and my connections work fine, which puzzles me.To describe precisely my configuration, both my client and my server are using a Swift framework using network.framework. They are both C++ applications, running on the same machine (development environment). Communication between the C++ and Swift part of the application is fine.I manage properly to create connections and send data over them. If I cancel the connection either client or server side, the other side never gets notified. Same behavior occurs if I kill the client or the server. If I test my code on a simple Swift project, it works fine. The Swift code must be inside a framework, in my opinion, for the issue to happen.I've looked at everything during 2 days, and I don't think I make any obvious mistake. The fact that I receive all the other states properly make me think there's an issue with the specific way failed and cancelled statuses are handled.Thanks for any help you can give me.
Post not yet marked as solved
My question is regarding https://forums.developer.apple.com/thread/15508As you told its constraint isn't technical, its question of legitimacy what I understood from your comment. System Guard & apps like cisco anyconnect, how they are working if they are not accessing routing tables?Can it be done using network extensions?
Subject says basically all. I have a CarPlay audio app whose network accesses (started answering playableContentManager(_:,initiatePlaybackOfContentItemAt:, completionHandler:)) fails when the application is started from the CarPlay screen with the phone locked.All calls are https; no data protection active; the app works correctly when cached content is played (ie: it's the network access that fails); the app works correctly if the phone is unlocked.I'd say this started around iOS12 (I'm not sure, though)... it was working when I started implementing CarPlay (~iOS10).I cannot find any documentation for the behaviour. Is this expected (and there is some workaround) or should I file a bug against CarPlay?Thank you in advance!
Post not yet marked as solved
I want to track iOS device's Ip address and submit it to server for fraud detection purpose.so#1. In iOS 12 using swift language, can we access device ip address without any restriction?#2. Whether apple allowed to track device ip address and is there any public API provided by apple to track device ip address?#3. if we track device IP address wther apple reject app on appstore?
Post not yet marked as solved
Hello everyone,I'm using TCP socket for communication between devices in my apps. So far I've been experiencing a latency problem with sending/receiving messages via the socket. According to this topic here http://www.stuartcheshire.org/papers/nagledelayedack/ , the problem might probably due to Nagle Algorithm and Delay ACK.After some research, I'm able to set TCP_NODEDELAY for my socket by using this code:int nodelay_flag = 1;setsockopt(*sock, IPPROTO_TCP, TCP_NODELAY, (void*) &nodelay_flag, sizeof(int))However I still cannot disable Delay ACK. I'm told that TCP_QUICKACK will solve the problem, but when I write this code:int quickack_flag = 1;setsockopt(*sock, IPPROTO_TCP, TCP_QUICKACK, (void*) &quickack_flag, sizeof(int))I got the error from compiler error: "Use of undeclared identifier 'TCP_QUICKACK' ". Can someone please help me with this? Thanks a lot in advance.
We're writing a Network.framework version of our peer-to-peer video streaming implementation, and are running into issues when the UDP message size becomes large enough to cause fragmentation. When this happens, it fails to reassemble with the following error:nw_protocol_ipv6_process_reassembly [C5.1:2] Failed to reassemble IPv6 Fragmentation ID 4293396248, dropping 1 framesThis happens both over en0 and awdl0. Any insights as to why this is happening would be greatly appreciated!
Post not yet marked as solved
Xcode 11 beta 3, iOS 13 in plist I have:<key>NSAllowsArbitraryLoads</key><true/>And all http requests work prior iOS 13. In iOS 13 I'm seeing in console:Cannot start load of Task <...>.<1> since it does not conform to ATS policy Task <...>.<1> finished with error [-1022] Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.,Is ATS policy have been changed in iOS 13? I can't find any info about it.
Hi,I wanted to try using the new NWBrowser available in iOS 13 to replace my old Bonjour browsing code, problem is I'm unabe to get the IP and Port of the service I'm looking for.My code :let params = NWParameters()
params.includePeerToPeer = true
_bonjourBrowser = NWBrowser(for: .bonjour(type: "_mpd._tcp.", domain: nil), using: params)
_bonjourBrowser.browseResultsChangedHandler = { results, changes in
for change in changes {
switch change {
case .added(let browseResult):
switch browseResult.endpoint {
case .hostPort(let host, let port):
print("added hostPort \(host) \(port)")
case .service(let name, let type, let domain, let interface):
print("added service \(name) \(type) \(domain) \(String(describing: interface))")
default:
print("fail")
}
case .removed(let browseResult):
print("removed \(browseResult.endpoint)")
case .changed(_, let browseResult, let flags):
if flags.contains(.interfaceAdded) {
print("\(browseResult.endpoint) added interfaces")
}
if flags.contains(.interfaceRemoved) {
print("\(browseResult.endpoint) removed interfaces")
}
default:
print("no change")
}
}
}
_bonjourBrowser.start(queue: DispatchQueue.global())What I get is :added service MPD.PI _mpd._tcp local. niladded service MPD.MBP _mpd._tcp local. nilHow can I get an IP and Port out of this ?
Post not yet marked as solved
HiI'm using an iphone x with ios 13.1 to test my app but when I try to call my backend deployed on aws and covered by an aws certificate the app throws this error:2019-10-01 15:29:04.099537+0200 CopApp[2120:565037] [] tcp_input [C2.1:3] flags=[R.] seq=1248880982, ack=548775464, win=28408 state=ESTABLISHED rcv_nxt=1248880982, snd_una=5487754642019-10-01 15:29:04.104758+0200 CopApp[2120:565037] Connection 2: received failure notification2019-10-01 15:29:04.104938+0200 CopApp[2120:565037] Connection 2: received ECONNRESET with incomplete TLS handshake - generating errSSLClosedNoNotify2019-10-01 15:29:04.105080+0200 CopApp[2120:565037] Connection 2: failed to connect 3:-9816, reason -12019-10-01 15:29:04.105289+0200 CopApp[2120:565037] Connection 2: encountered error(3:-9816)I don't know why this error is returned because I read all new apple's certificates policies but it seems that aws certificates completely fullfill them.Can you help me?Thanks
Post not yet marked as solved
Hi, I am unable to figure out how to set the tls protocol version. This is part of the code I am using:let tlsOptions = NWProtocolTLS.Options()
sec_protocol_options_add_pre_shared_key(...)
sec_protocol_options_add_tls_ciphersuite(tlsOptions.securityProtocolOptions, TLS_PSK_WITH_AES_128_GCM_SHA256)
sec_protocol_options_set_min_tls_protocol_version(tlsOptions.securityProtocolOptions, tls_protocol_version_t.DTLSv12)
let parameters = NWParameters(dtls: tlsOptions)
connection = NWConnection(host: ..., port: NWEndpoint.Port(rawValue: 2100)!, using: parameters)
connection.start(queue: .main)When I run this code I get the following log errors:2019-10-19 14:30:31.628250+0200 MyApp[4906:117290] [BoringSSL] boringssl_helper_tls_protocol_version_from_SSLProtocol(111) [C6:1][0x7fd33fc4d4f0] Unknown SSLProtocol version: 11
2019-10-19 14:30:31.649137+0200 MyApp[4906:117290] [BoringSSL] boringssl_context_handle_fatal_alert(1874) [C6:1][0x7fd33fc4d4f0] read alert, level: fatal, description: bad record mac
2019-10-19 14:30:31.650008+0200 MyApp[4906:117290] [BoringSSL] boringssl_session_handshake_error_print(111) [C6:1][0x7fd33fc4d4f0] 140546626918936:error:100003fc:SSL routines:OPENSSL_internal:SSLV3_ALERT_BAD_RECORD_MAC:/BuildRoot/Library/Caches/com.apple.xbs/Sources/boringssl_Sim/boringssl-283.40.1/ssl/tls_record.cc:587:SSL alert number 20
2019-10-19 14:30:31.650105+0200 MyApp[4906:117290] [BoringSSL] nw_protocol_boringssl_handshake_negotiate_proceed(724) [C6:1][0x7fd33fc4d4f0] handshake failed at state 12288It appears that the tls protocol version is unknown (see first log line). This is the function I am using to set the version: https://developer.apple.com/documentation/security/3180218-sec_protocol_options_set_min_tlsI am using the `tls_protocol_version_t.DTLSv12` constant so why does this show an error? I was unable to find any documentation/samples using DTLS so I might be doing something wrong. Is this the correct way to use DTLS?
-bash: rvictl: command not found
Post not yet marked as solved
According to Wikipedia, Wi-Fi TDLS has been around for a number of years. Does iPhone (any model) support TDLS? If yes, how does it work? Does it need any help from the app by any means or fully automatic? Thanks in advance.
Post not yet marked as solved
I’m trying to use NWPathMonitor in my watchOS 6 app. The weird thing is that it works fine in Simulator, but is never ‘satisfied’ on a real device. Is there a reason why this is so? If it is a limitation of a real device, then perhaps Simulator should reflect that limitation. If it’s not a limitation, then how can I coax the device to return ‘satisfied’?