Is the iPhone always using Wifi (instead of cellular data network) when connected?
I believe you cannot chose programmatically whether to use the WiFi or the cellular data connection.

If the iPhone has a WiFi network available, it will automatically use it, otherwise, it will fallback on the cellular data connection.