Forum Xamarin.Forms

How do I calculate total data consumed per application in IOS?

Hi all, Im working on an app where I need to monitor the total data consumed by the app. I successfully got the total data consumed by the IPhone but i'm not able to calculate the data consumed by my app alone. I found a post where it states that, it is possible to get data consumed per app by get the current running Process. I have the code in Obj c but I don't know how to convert it into c#. Can anyone help me? Thanks in advance:
(NSArray *)runningProcesses { int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0}; size_t miblen = 4; size_t size; int st = sysctl(mib, miblen, NULL, &size, NULL, 0); struct kinfo_proc * process = NULL; struct kinfo_proc * newprocess = NULL; do { size += size / 10; newprocess = realloc(process, size); if (!newprocess){ if (process){ free(process); } return nil; } process = newprocess; st = sysctl(mib, miblen, process, &size, NULL, 0); } while (st == -1 && errno == ENOMEM); if (st == 0){ if (size % sizeof(struct kinfo_proc) == 0){ int nprocess = size / sizeof(struct kinfo_proc); if (nprocess){ NSMutableArray * array = [[NSMutableArray alloc] init]; for (int i = nprocess - 1; i >= 0; i--){ NSString * processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid]; NSString * processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm]; NSString * processState = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_wmesg]; NSDictionary * dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName,processState, nil] forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName",@"ProcessState", nil]]; // [processID release]; // [processName release]; [array addObject:dict]; // [dict release]; } free(process); return array; //autorelease]; } } } return nil; }

Sign In or Register to comment.