I want my application to use cellular data when WI-FI is On.
For that, I need access to socket before it is connected
so that it can be bound to cellular network IP and port.
Thought of using CFStreamCreatePairWithSocket() instead of CFStreamCreatePairWithSocketToHost()
but stream callbacks are not received.
Steps.
1. Create socket with CFSocketCreate() function
2. Get a native socket using CFSocketGetNative() and bind it to cellular IP.
3. Make a connection using CFSocketConnectToAddress() with timeout
parameter as -1 (Need a non-blocking connect).
4. Scheduled it over run loop using CFRunLoopAddSource
5. Upon kCFSocketConnectCallBack call back event create streams using
CFStreamCreatePairWithSocket().
6. Assigns clients to a streams for stream events.
7. Scheduled streams over run loop and opened the stream.
Expected Results:
1. Receive socket call back events.
2. Receive stream call backs events.
Actual Results:
1. Received kCFSocketConnectCallBack once and kCFSocketWriteCallBack twice. Rest events are not received.
2. Received only kCFStreamEventOpenCompleted.
Version/Build:
10.3.2
Kindly, let me know if I am missing something in above steps or there is any different way to do this.
Is there any API at application level instead of socket level to force application to use cellular network
when wifi is ON?