WatchOS6 missing module CFNetwork

Hi,


I am jumping into WatchOS6 never having used previous versions of WatchOS, I do have years of experience with ObjC / Swift / Xcode though. I am trying to create an independent Watch App and have started with the Networking by dragging over the code from my main App into the WatchKit Extension target. I cannot get it to compile due to "No such module CFNetwork" error at the import CFNetwork statement in the file where I use CFNetwork to compare the errors such as CFNetworkErrors.cfurlErrorNotConnectedToInternet.


According to docs CFNetwork is available on WatchOS 2.0+ and I have added CoreServices.framework and MobileCoreServices to the target.


Am I doing anything obviosly wrong here?


Cheers,

Brett

Replies

I got exactly the same issue. CFNetwork should be importable after WatchOS 2.0 but it seems not to be in the list of frameworks. I'm also running the xcode beta version.

Hi! I'm also having problems with CFNetwork in watchOS 6 beta 6. I'm using URLSessionWebSocketTask and the app seems to crash because it's missing access to something in the CFNetwork framework.

This is a simplified version of my code:

let url = URL(string: “ws://127.0.0.1:8080”)!
let urlSession = URLSession(configuration: .default)
let task = urlSession.webSocketTask(with: url)
self.webSocketTask = task
task.resume()


(I've set up a local websocket server, but also tried with public websocket 'echo' servers)


When trying to connect with the code above, the app crashes and I don't get any error messages in the "Debugger output", but I do get the following output in the "Debug navigator":


CFNetwork`___lldb_unnamed_symbol9369$$CFNetwork:

[... Lots of instructions ....]

os_log_type_enabled

0x4286c54a <+446>: testb %al, %al

0x4286c54c <+448>: jne 0x4286c6b3 ; <+807>

0x4286c552 <+454>: movl %esi, (%esp)

0x4286c555 <+457>: calll 0x428e87de ; symbol stub for: objc_release

0x4286c55a <+462>: movl -0x30(%ebp), %eax

0x4286c55d <+465>: movl 0x250292bf(%eax), %eax

0x4286c563 <+471>: movl (%ebx,%eax), %eax

-> 0x4286c566 <+474>: movl (%eax), %ecx

[... Lots of more instructions ....]


And on the left hand side in xcode, it says

0___lldb_unnamed_symbol9369$$CFNetwork

I've tried lots of things like variations on the code, trying to import the CFNetwork framework with no luck.
If I understand this correctly "lldb_unnamed_symbol" is becuase the app is missing a library it's trying to use.
So it seems to me like the implementation of URLSession (which is new in watchOS 6) is incomplete in some way that's connected to the CFNetwork framework
Any Apple people here to help out?

In the latest beta - watchOS 6 beta 7, it says in the release notes that:

Networking


New Features

  • To enhance security,
    URLSession
    no longer sniffs the MIME type when the server sends
    Content-Type: application/octet-stream
    . (7820658)
  • NSURLRequest.CachePolicy.reloadRevalidatingCacheData
    and
    NSURLRequest.CachePolicy.reloadIgnoringLocalAndRemoteCacheData
    APIs are now available. (49660334)
  • URLSessionWebSocketTask
    and
    URLSessionStreamTask
    are now available for use in watchOS apps. (49779789)


However, after installing beta 7 on my apple watch, I still get the exact same crash.

I have also meet the same issue, what I did is try to migrate an iOS static library which base on CFNetwork to WatchOS. Do you have find the solution?

I am also getting this error. Did you ever manage to solve it? task.resume() does not cause a crash for me when the websocket server is wss://echo.websocket.org (a public websocket test server). However, when I use my own websocket server, it causes a crash, even though my server works when invoked from other platforms/frameworks (such as React Native). Thanks.

Did you guys ever happen to find a solution?

CFNetwork is still not listed under frameworks for WatchOS although it should be according to the docs