ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
473 stars 209 forks source link

get adapter object in UI Controller #101

Closed hungrytocode closed 5 years ago

hungrytocode commented 5 years ago

i want to use transportStatistics property in OpenVPNAdapter class ,but how can i transport this property in PacketTunnelProvider.m class to my UI controller to use this property.

ss-abramchuk commented 5 years ago

Hi @hungrytocode, you don't need adapter in the main app. It is sufficient to send just statistic there. You can do it using UserDefaults initialized with custom suite name.

hungrytocode commented 5 years ago

Hi @hungrytocode, you don't need adapter in the main app. It is sufficient to send just statistic there. You can do it using UserDefaults initialized with custom suite name.

oh,thanks,and can you tell me where i can write data with UserDefaults in extension and where i should read data with UserDefaults in main app.

swati-daffodilsw commented 5 years ago

@hungrytocode : you can also fetch traffic stats without using Userdefaults by the following way.

You can use func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) delegate method of NEPacketTunnelProvider and fetch transport stats using vpnAdapter.transportStatistics.bytesIn and vpnAdapter.transportStatistics.bytesOut.

In your host app, you can fetch session from providerManager?.connection as? NETunnelProviderSession instance and then use method sendProviderMessage

I hope it will help you!!

kasra7272 commented 3 years ago

hi , what I get when using vpnAdapter.transportStatistics.bytesOut/bytesIn is zero all the time, can you explain more with an example??