WatchOS & NSURLSessionStreamTask

Having major issues getting any networking working on WatchOS 2. See this thread and the sub-threads for more related from others as well:


https://forums.developer.apple.com/message/30666


Anyway, at this point will try anything. Thinking maybe Apple only intended NSURLSession to work on WatchOS and everything else is broken by design even though everything except some NSStream oddities works great on the WatchOS 2 Simulator.


Thus, converting everything to NSURLSessionStreamTask. I'm not sure this class is ready for prime time, or maybe I'm not clear on how it's used as there's no sample code. The basic sequence of streamTaskWithHostName then resume opens and then immediately closes a connection which I've verified by sniffing packets. The connection is closed well before I can read or write it. This has been the case for many betas and continues in b5.


So the questions are:


1. Is NSURLSession the only way to perform networking on WatchOS 2 as it seems? Or are these issues in betas 1 through 5 just bugs and I should go on using the Simulator happily, knowing sockets will work.


2. If it is not, what are the networking APIs we can rely upon going forward in WatchOS 2? We are heavily based on UDP under normal circumstances, but we can live with TCP if there's no other choice. Since all of them seem non-functional right now, I'd at least like to get a correct answer of what is expected to work so we stop going down these dead ends.

I even tried converting everything to NSURLSessionStreamTask [...] may suffice for us short term for basic networking, but that class doesn't seem to be in a functional state yet either even on straight iOS 9.

On the iOS side of things, it seems that you're seeing a bug in NSURLSession's stream task support. I tried this out for myself (or 9.0b5) and got similar results. I've filed this as 22213450.

On the watchOS side of things, I think the problem you're having is that the watch does not have an active network interface, at least not most of the time. Most of the time the paired iPhone is available and the watch pushes networking requests off to that. If the paired iPhone is not available then the watch can join Wi-Fi networks, but that only happens under specific circumstances and opening a TCP connection is not one of them.

I'm not sure that NSURLSession stream task will help with this, even once it starts working in general.

For the moment I think your best option is either talk to your target device via HTTP[S] or move that work to your iOS app.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I just wanted to clarify my earlier comments:

On the watchOS side of things, I think the problem you're having is that the watch does not have an active network interface, at least not most of the time.

While that’s true, it’s not the full story. Since posting this I’ve learnt more about the networking capabilities of code running on the Watch. I posted the details to this thread.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
WatchOS & NSURLSessionStreamTask
 
 
Q