How to programmatically turn on/off WiFi in iOS? [Swift]

NOTE: I am aware that such a thing violates user's privacy and would be rejected by Apple. However, this specific component is purely for automated testing of buffering behavior when the user's connection is poor/nonexistent. It will NOT be publicly released.

With that said, does anyone know of a way to programmatically turn on/off WiFi in iOS?

I have not been able to find anything up-to-date. Pretty much every answer has to do with this being a violation of privacy and cautioning that they shouldn't do it. Doesn't apply in my case.

Closest I could find was using something like DeviceFarm to simulate it https://docs.aws.amazon.com/devicefarm/latest/developerguide/how-to-simulate-network-connections-and-conditions.html

However, in my case I want these tests to run entirely within the app (private test build). Setting up DeviceFarm for this purpose alone isn't worth it imo.


There is no provision provided by apple to change automate changing its settings because of apple's privacy rule. So you can't achieve by any way.