如何获取后台运行应用程序的名称 [英] How to get Names of Background Running Apps

查看:137
本文介绍了如何获取后台运行应用程序的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我需要显示在后台运行的应用程序的名称。我做了R& D,并且知道我们只知道Apple的应用程序,如照片,相机等。但我不知道如何。如果您知道如何获得背景运行应用程序的名称,请帮助我 b对于后台运行进程我使用了以下方法

I'm making an app in which i need to show the names of apps running in background. I did R&D on it and came to know that we can know only about Apple's apps like Photos , Camera etc. But I couldn't know how. Please help me if you know how to get JUST NAMES OF BACKGROUND RUNNING APPS For Background running processes I have used following Method

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

如果你觉得它不可能那么请看看这款应用 http://itunes.apple.com/us/ app / sys-activity-manager-for-memory / id447374159?mt = 8 。我也有一个解决方案,但它不是一个正确的方法(我已经在下面的问题中提到了这个问题)。

If you think its impossible then kindly have a look to this app http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8 . I have also got a solution but its not a proper way (I've mentioned in the last comment below this question).

谢谢。

推荐答案

我认为在ios中无法获得哪些应用程序在后台运行,因为在ios中哪一个是前景,这一个是活动的运行应用程序和其他你得到的这些都是背景appps。

I think in ios it not posible to get which apps are running in background, because in ios the which one is foreground this one the active running apps and other which one you are getting these all are background appps.

因此,不包括您的应用程序名称,其他人是后台应用程序。

so, excluding your application name others are background apps.

这篇关于如何获取后台运行应用程序的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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