11

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

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).

Thanks.

HarshIT
  • 4,583
  • 2
  • 30
  • 60
  • Had you go through this http://forrst.com/posts/UIDevice_Category_For_Processes-h1H – Mehul Mistri Mar 29 '12 at 04:32
  • Perhaps where it says ProcessName in your above code? – Adam Shiemke Mar 29 '12 at 04:32
  • @AdamShiemke, that's what is giving the processes not NAME of App,processes means all background running services – HarshIT Mar 29 '12 at 04:35
  • You certainly can't do that in a way that will let your app go to the app store. I'm fairly sure there is no good way to extract the app names from processes, but I could be wrong. – Adam Shiemke Mar 29 '12 at 17:27
  • @AdamShiemke , see this http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8 This app is able to show the name of currently running apps. – HarshIT Mar 30 '12 at 04:14
  • 1
    Hmmm... there must be some way to do it that I'm not thinking of. – Adam Shiemke Mar 30 '12 at 04:34
  • Probably , every apps (provided by apple like Photos, Camera etc) have their fixed process ID on basis of that we can detect which app is running. @AdamShiemke – HarshIT Mar 30 '12 at 04:53
  • I've got temporary solution of my problem, although its not a proper way.I couldn't find any other option. I ran every app one by one and checked the process name from the above coding for that app. So if a process name comes related with App , we can say that The App is running. For ex. If " MobileSMS" named process runs , iMessage App is running in Background. Thus I got all Apple's apps and their related process names. – HarshIT Apr 04 '12 at 09:27

2 Answers2

1

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.

Saroj Ojha
  • 79
  • 2
  • 4
  • see http://itunes.apple.com/us/app/sys-activity-manager-for-memory/id447374159?mt=8 . , this works fine. That means this is possible – HarshIT May 16 '12 at 04:28
0

I don't think it's ment to be possible, but others like you have been very involved in the same topic and come up with some workarounds. Read this blogpost for more info: http://www.amitay.us/blog/files/how_to_detect_installed_ios_apps.php

jornare
  • 2,903
  • 19
  • 27