Low-Level Networking on watchOS

This thread has been locked by a moderator; it no longer accepts new replies.

This post has now been deprecated in favor of: TN3135: Low-level networking on watchOS - https://developer.apple.com/documentation/technotes/tn3135-low-level-networking-on-watchos


Prior to watchOS 6 there was no support for low-level networking APIs in watchOS. watchOS 6 does support the use of Network framework, but only in the context of an audio streaming session. Low level networking APIs such at Network framework, BSD Sockets, and socket streams that are used outside the context of an audio stream session on watchOS will not work as expected and may result in inconsistent behavior compared to iOS. If you are not working on an audio app and wanting to utilize Network framework it’s best to do this work on iOS.

For higher level network API functionality, such as making HTTPS requests, my recommendation is to use NSURLSession for HTTPS requests as this continues to work as it always has on watchOS. Note that NSURLSession tasks such as NSURLSessionWebSocketTask and NSURLSessionStreamTask do not work on watchOS as these tasks still considered low level networking APIs. For HTTPS requests I would recommend using NSURLSessionDataTask.

For more information on networking on watchOS, see the following 2019 WWDC session on Streaming Audio on watchOS 6.

Matt Eaton DTS Engineering, CoreOS meaton3@apple.com

Change history:

  • 14th May 2021 - Updated to call out that NSURLSessionWebSocketTask and NSURLSessionStreamTask are not supported on watchOS.
Answered by DTS Engineer in 730252022

This post has been replaced by a shiny new technote, TN3135 Low-level networking on watchOS.

I’ve left the original post here just for the record, but I’ve locked this thread. If you have questions or comments about networking on watchOS, please start a new thread. Make sure to tag it based on the API you’re using, so CFNetwork if you’re using URLSession or Network if you’re using Network framework.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Boost

Is there any change to this with watchOS 8?

I looked into the update status for this on watchOS 8 and as of 17th June 2021, there was no update on this matter for watchOS 8.

Matt, the watchOS 6 release notes here state that "URLSessionWebSocketTask and URLSessionStreamTask are now available for use in watchOS apps. (49779789)”. What gives?

@RandomizedUser Those APIs were made available for the use of audio streaming sessions.

Right, as @WatchLucas has mentioned, these APIs are available in the context of an audio streaming session.

@meaton, could you clarify what does "context of an audio streaming session" means? With CallKit available on watchos9 I'm trying to figure out how to stream audio with RTP. I have 'audio' backgrounding mode, audio session started and audio initialised with AVAudioEngine. Is it in audio streaming session context or it's not? I'm still getting "Path was denied by NECP policy" (using 'Network.framework')

When I've tested this on watchOS I've setup a AVAudioSession that pulls is responsible for handling any kind of audio and then Network framework is responsible for pulling in either meta data for the audio stream, or the stream data itself. I have not tested this with CallKit involved.

@meaton can you clarify why my app was approved and ran perfectly fine from watchOS 7 until 8.7 using WebSockets? My entire app foundation was built relying on that functionality which only stopped working on watchOS 9, and the documentation for NSURLSessionWebSocketTask still lists watchOS as supported.

Now my app stopped working for users that upgraded and I’ll have to spend a lot of work to reengineer my application to use a polling mechanism instead.

This post has been replaced by a shiny new technote, TN3135 Low-level networking on watchOS.

I’ve left the original post here just for the record, but I’ve locked this thread. If you have questions or comments about networking on watchOS, please start a new thread. Make sure to tag it based on the API you’re using, so CFNetwork if you’re using URLSession or Network if you’re using Network framework.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Low-Level Networking on watchOS
 
 
Q