Searching for installed apps

Discussion in 'iOS Programming' started by mycompuser, Aug 11, 2014.

  1. mycompuser macrumors member

    May 8, 2012
    Hi All,

    I am investigating for a feature for my iOS app (iOS 6 and above) where I will be given a list of conflicting apps (these apps might not work as expected along side my app).

    I have to check if an app (from the list) are already installed, if so need to prompt an warning msg to my user about the possible conflict.

    Did some googling to try to find a solution to get list of installed apps on my iPhone/iPad but no success.

    The nearest I could get was the solution which did not work for me is made available at this page. Tried running the code but the cacheDict is always empty.

    I think they are using private api's which I would like to avoid as there is a change for apple to reject my app for app store.

    Can you guys please guide me with a solution to the issue?

    Thanks in advance.
  2. mycompuser thread starter macrumors member

    May 8, 2012
    Hi All,

    Have discovered that one method to find whether an app is installed or not on a device is using custom URL Scheme.

    Here is a link to the detailed explanation on the same.

    But as configuring an URL Scheme is not mandatory for an app, relying on URL Scheme along for determining if an app is installed or not i feel might not be reliable.

    Is there any other way by which we can figure out if an app is installed or not?
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Custom URL Schemes is the only non-private way I know to detected installed apps.
  4. mycompuser thread starter macrumors member

    May 8, 2012
    Hi dejo,

    Thanks for the reply.

    If that is the case, I am thinking of using custom URL Schemes along with process name of an app to determine if the application is installed on the device or not.

    So I would first search for Custom URL Scheme. If no conflicting apps are found, then I would look for the process name (of the conflicting app) from the list of running process on the device. (for this approach, I'll need process name and custom URL scheme (if any) of all the conflicting apps).

    Of course, with this approach I will not be able to detect an conflicting app which has not configured Custom URL Scheme and which is not running (in the background) at the movement.

    Are there any caveat that I have overlooked with this approach?

    Can somebody suggest me a better approach if any?

    Advance thanks.
  5. JohnsonK macrumors regular

    Mar 6, 2014
    Are you developing for the app store or cydia?
  6. fishkorp macrumors 68020


    Apr 10, 2006
    Ellicott City, MD
    I don't think you can get the running processes via public APIs, can you? What you're trying to do would require a jailbroken phone I think.
  7. mycompuser thread starter macrumors member

    May 8, 2012
    Hi All,

    The product is for App store.

    I thought sysctl was not a private api. Is it not?

    I actually extracted the below method code to return list of running process from an iOS project from github.

    Am I doing something wrong (am I using private api)?

    - (NSArray *) _sysctl_ps {
        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){
                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]];
                        [array addObject:dict];
                    return array; 
        return nil;
  8. JohnsonK macrumors regular

    Mar 6, 2014
    This will definitely get you rejected

    XCode even will probably reject it before you can submit it to app store
  9. ArtOfWarfare macrumors G3


    Nov 26, 2007
    This is an XY problem and I don't know why everyone is focused on Y.

    Your X is that you think your app could conflict with other apps. Pray tell, how could your app, which is sandboxed, could possibly conflict with other apps, which are also sandboxed? The fact that your app can't even figure out if the other app is installed or not strongly suggests you wouldn't be able to even have a conflict between the two apps.
  10. mycompuser thread starter macrumors member

    May 8, 2012
    Hi ArtOfWarfare,

    My app register with an apple framework (private framework exposed to us by Apple). But my competitor (conflicting app) can also register for events from that framework as he too has access to the private framework by apple.

    So on some user action, the framework fires a notification/event, which is handled both by my app and my competitor's app. As we both use the same framework, there is a possibility of conflict.

    This case we are trying to handle by showing some msg informing user of possible conflict.
  11. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Err... what? This sounds like you probably just violated an NDA if you're using a private framework Apple is giving you special permission to see.

    I don't see the conflict. You're replying to a notification and so is the competing app - there's no conflict from both of you receiving a notification. The only way I can see them causing a conflict is if they're both trying to manipulate a shared resources in different ways, but you didn't describe a scenario like that, yet.
  12. mycompuser thread starter macrumors member

    May 8, 2012
    I think that is the scenario that they are trying to handle (As that module was developed by another member of my team I am not aware of the details).

    If call to sysctl to get background process is an private api, then how come there are so many apps in the app store which do just that (list running process and other info)? Search for "activity monitor" in iTunes. I assume that they too must be using sysctl to get process list?

Share This Page