我们可以检索当前在 iPhone 和 iPad 上运行的应用程序吗 [英] Can we retrieve the applications currently running in iPhone and iPad

查看:41
本文介绍了我们可以检索当前在 iPhone 和 iPad 上运行的应用程序吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以检索当前在 iPhone 和 iPad 上运行的应用程序吗?

Can we retrieve the applications currently running in iPhone and iPad?

更新

我们可以在监狱坏掉的手机上做吗?我们可以为 CYDIA 商店的应用程序做吗?

Can we do it in jail broken phones? Can we do it for an app for CYDIA Store?

推荐答案

您可以获得正在运行的进程列表,并且从进程 ID 中您可以找出哪些是系统进程,哪些是 3rd 方应用程序,但无论如何我不相信你可以在 appstore 的应用程序中使用它.(代码取自此处)

You can get a list of running processes and from process ids may be you can figure out which ones are system processes and which one are 3rd party apps, but anyway I don't believe you can use it in application for appstore. (code taken from here)

- (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 autorelease];
            }
        }
    }

    return nil;
}:

这篇关于我们可以检索当前在 iPhone 和 iPad 上运行的应用程序吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆