How to collect internet usage information for iPhone with Xamarin / monotouch

Asked

Viewed 77 times

1

I need to collect internet usage information on iphone , the code c# below that I am using only returns me zeroed values.

I’m using the right class ?

has some reference I need to add on Xamarin ?

in the mono appears me 3 types of classes , concidently the interface "Macosipv4interfacstatics" returns fixed always the value 0.

https://github.com/mono/mono/blob/master/mcs/class/System/System.Net.NetworkInformation/IPv4InterfaceStatistics.cs

  1. Win32ipv4interfacstatics
  2. Linuxipv4interfacestatistics
  3. Macosipv4interfacstatics

    using System;
    using System.Net;
    using System.Net.NetworkInformation;
    using System.Runtime.InteropServices;
    using System.Threading;
    using MonoTouch.ObjCRuntime;
    

    namespace Taximetro { public delegate void Update();

    public static class ControleUso
    {
        public static long controller;
    
        public static long BytesReceivedWiFi;
        public static long BytesSentWiFi;
    
        public static long BytesReceived3G;
        public static long BytesSent3G;
    
        public static Update UpdateMethod;
    
        public static void DoWork()
        {    
            foreach (var netint in NetworkInterface.GetAllNetworkInterfaces()) {
                var stats = netint.GetIPv4Statistics ();
    
                //WiFi
                //if (netint.Name.StartsWith ("en")) {
                    BytesReceivedWiFi += stats.BytesReceived;
                    BytesSentWiFi += stats.BytesSent;
                //}
    
                //3G
                if (netint.Name.StartsWith ("pdp_ip")) {
                    BytesReceived3G += stats.BytesReceived;
                    BytesSent3G += stats.BytesSent;
                }
            }
            controller++;
            if (UpdateMethod != null) {
                UpdateMethod ();
            }
            Thread.Sleep (1000);
        }
    }
    

    }

  • Replied via the link http://stackoverflow.com/questions/26256093/how-to-collect-data-usage-information-from-the-internet-to-iphone-with-xamarin

  • Bring the answer here. Post as an answer and accept it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.