Reputation: 4915
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.
Upvotes: 11
Views: 3311
Reputation: 79
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.
Upvotes: 1
Reputation: 2893
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
Upvotes: 0