Can we use socket streams in App Clips?

The following code can connect to the host successfully on iOS Simulator. But the code fails to connect on an iOS device. I has checked the WLAN and Cellular Data are both allowed for the app clip.

I also try NSURLSession to access to a web site. NSURLSession is successful to get the data on both iOS simulator and iOS devices.

Do we allow to use socket streams in App Clips?

Xcode Version 12.0 beta (12A6159)
iOS 14 Beta: 14.0

But the code fails to connect on
Code Block Objective-C
  CFReadStreamRef readStream;
  CFWriteStreamRef writeStream;
   
  //create socket connection
  CFStreamCreatePairWithSocketToHost(NULL, (bridge CFStringRef)@"www.baidu.com", 443, &readStream, &writeStream);
  NSInputStream* inputStream = (bridge_transfer NSInputStream*)readStream;
  NSOutputStream* outputStream = (__bridge_transfer NSOutputStream*)writeStream;
     
[inputStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL
           forKey:NSStreamSocketSecurityLevelKey];
  // and open the streams
  [inputStream open];
  [outputStream open];

Console output:
Code Block
[connection] nw_socket_connect [C1.1:1] connectx(5, [srcif=0, srcaddr=<NULL>, dstaddr=61.135.169.121:443], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [65: No route to host]
[connection] nw_socket_connect [C1.1:1] connectx failed (fd 5) [65: No route to host]
[] nw_socket_connect connectx failed [65: No route to host]
[connection] nw_socket_connect [C1.2:1] connectx(5, [srcif=0, srcaddr=<NULL>, dstaddr=61.135.169.125:443], SAE_ASSOCID_ANY, 0, NULL, 0, NULL, SAE_CONNID_ANY) failed: [65: No route to host]
[connection] nw_socket_connect [C1.2:1] connectx failed (fd 5) [65: No route to host]
[] nw_socket_connect connectx failed [65: No route to host]
[connection] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection
TCP Conn 0x280200370 Failed : error 0:65 [65]


Answered by Engineer in 618987022
socket streams are not allowed. The recommended way to access the network is via NSURLSession.
Accepted Answer
socket streams are not allowed. The recommended way to access the network is via NSURLSession.
have the same issue, socket cannot used in App Clips。
socket api can work in simulator but failed in device。
Can we get a bit more detail on why sockets aren't supported in app clips? Also why do they work on the simulator?
Why are socket streams disabled, and are there any plans to lift this restriction in a future version of iOS?

This prevents all sorts of interesting App Clips use-cases, for example anything involving WebRTC (all sorts of audio and video communications tools).

Example of how this prevents any app relying on the Twilio Video or Audio iOS SDKs from supporting an associated App Clip:
https://github.com/twilio/twilio-voice-ios/issues/65

With iOS 16 coming out I was wondering if there are any updates on this? I see App Clips are expanding to 15mb, but are there any plans to allow socket streams at some point in the future? With the impact of covid and the expanded use of video conferences it would be nice to be able to have an app clip that could handle one.

Can we use socket streams in App Clips?
 
 
Q