3

My app is made available in App Store and hence cannot use private api's.

Would like to know that whether the call to sysctl to get the list of background process is a private api call? Below is the code snipper to get the list of running process.

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];

                    NSDictionary *dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] 
                                                                       forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];
                    [processID release];
                    [processName release];
                    [array addObject:dict];
                    [dict release];
                }

                free(process);
                return array;
            }
        }
    }

    return nil;
}
Marimuthu
  • 437
  • 4
  • 14

2 Answers2

4

There is a very helpful tool you can use called Appscanner

https://github.com/ChimpStudios/App-Scanner

App Scanner is a preflight submission check list for iOS developers. It searches code for private API usage.

It should catch most private API usage.

You can use App Scanner one of three ways: drop a compiled simulator .app folder into the GUI to scan the app, type method signatures into the search text field, or integrate the command line version into your build phase as part of a script to automatically check code right after it is compiled by Xcode.

Basically the author has a dump of the private API's and can check if you've utilized any.

As sysctl is a UNIX call I don't think it's private.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
2

No, this call isn't private. Apple allows its use (well, at least for now).

I have an app in the AppStore that does this.

Andrey
  • 1,561
  • 9
  • 12