get la list des applications installées sur iphone objective-c

J'ai une application qui a besoin d'get la list des applications installées (autres, éventuellement tierces) sur l'appareil. Comment ceci peut être fait? Ou peut-il être fait du tout?

Je doute que quelque chose soit disponible (si un iphone est jailbreaké et que l'user peut accéder au système de files, alors ce sera possible, mais je ne suis pas conscient de cela.), Mais vous pouvez utiliser le lien suivant et avec l'aide de ceci quelles sont toutes les applications sont présentes et vous pouvez personnaliser avec certains de vos besoins.

Vous pouvez scanner toutes vos applications via Apple private framework "MobileInstallationInstall".

La méthode est comme ci-dessous:

NSDictionary *options = [NSDictionary dictionaryWithKeyAndValues:@"ApplicationType",@"Any",nil] NSDictionary *apps = MobileInstallationLookup(options); 

il ne peut être utilisé que dans les appareils JB.

 -(NSArray *) installedApps { BOOL isDir enter code here= NO; NSDictionary *cacheDienter code herect; NSDictionary *user; static NSSsortingng *const cacheFileName = @"com.apple.mobile.installation.plist"; NSSsortingng *relativeCachePath = [[@"Library" ssortingngByAppendingPathComponent: @"Caches"] ssortingngByAppendingPathComponent: cacheFileName]; NSSsortingng *path = [[NSHomeDirectory() ssortingngByAppendingPathComponent: @"../.."] ssortingngByAppendingPathComponent: relativeCachePath]; if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir) // Ensure that file exists { cacheDict = [NSDictionary dictionaryWithContentsOfFile: path]; user = [cacheDict objectForKey: @"System"]; // Then all the user (App Store /var/mobile/Applications) apps } //NSLog(@"Installed Applications = %@",[user allKeys]); //return [user allKeys]; return nil; } 

cela vous donnera le tableau du nom de l'application installée en utilisant l'API privée

il n'y a pas d'API publique d'Apple pour récupérer une telle list à partir d'un appareil iOS (iPod Touch / iPhone / iPad)

Ce WONT donne la list des applications installées mais vous pouvez get la list des applications s'exécutant en arrière-plan et leurs process concernés par ce code.

appel de viewDidLoad –

 [self printProcessInfo]; 

.

 -(NSMutableSsortingng*) printProcessInfo { int mib[5]; struct kinfo_proc *procs = NULL, *newprocs; int i, st, nprocs; size_t miblen, size; /* Set up sysctl MIB */ mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_ALL; mib[3] = 0; miblen = 4; /* Get initial sizing */ st = sysctl(mib, miblen, NULL, &size, NULL, 0); /* Repeat until we get them all ... */ do { /* Room to grow */ size += size / 10; newprocs = realloc(procs, size); if (!newprocs) { if (procs) { free(procs); } perror("Error: realloc failed."); return (0); } procs = newprocs; st = sysctl(mib, miblen, procs, &size, NULL, 0); } while (st == -1 && errno == ENOMEM); if (st != 0) { perror("Error: sysctl(KERN_PROC) failed."); return (0); } /* Do we match the kernel? */ assert(size % sizeof(struct kinfo_proc) == 0); nprocs = size / sizeof(struct kinfo_proc); if (!nprocs) { perror("Error: printProcessInfo."); return(0); } printf(" PID\tName\n"); printf("-----\t--------------\n"); self.lists = [[NSMutableSsortingng alloc] init]; NSMutableSsortingng *localStr = [[NSMutableSsortingng alloc] init]; for (i = nprocs-1; i >=0; i--) { // printf("%5d\t%s\n",(int)procs[i].kp_proc.p_pid, procs[i].kp_proc.p_comm); localStr = [NSSsortingng ssortingngWithFormat:@"%@,\nPID:-%5d,\tPROCESS_NAME:-%s\n",localStr,(int)procs[i].kp_proc.p_pid, procs[i].kp_proc.p_comm ]; NSSsortingng *pathStr = [self print_argv_of_pid:(int)procs[i].kp_proc.p_pid]; //NSSsortingng *pathStr = print_argv_of_pid:(((int)procs[i].kp_proc.p_pid)); localStr = [NSSsortingng ssortingngWithFormat:@"%@,\n%@\n",localStr,pathStr ]; // [self getAtsortingbutesOfProcess]; //printf("%s",path); } NSLog(@"%@",lists); free(procs); return localStr; //return (0); } -(NSSsortingng*) print_argv_of_pid:(int) pid { char path[1000]; printf("%d\n", pid); int mib[3], argmax, nargs, c = 0; size_t size; char *procargs, *sp, *np, *cp; extern int eflg; int show_args = 1; mib[0] = CTL_KERN; mib[1] = KERN_ARGMAX; size = sizeof(argmax); if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1) { return @""; //goto ERROR_A; } /* Allocate space for the arguments. */ procargs = (char *)malloc(argmax); if (procargs == NULL) { return @""; //goto ERROR_A; } /* * Make a sysctl() call to get the raw argument space of the process. * The layout is documented in start.s, which is part of the Csu * project. In summary, it looks like: * * /---------------\ 0x00000000 * : : * : : * |---------------| * | argc | * |---------------| * | arg[0] | * |---------------| * : : * : : * |---------------| * | arg[argc - 1] | * |---------------| * | 0 | * |---------------| * | env[0] | * |---------------| * : : * : : * |---------------| * | env[n] | * |---------------| * | 0 | * |---------------| <-- Beginning of data returned by sysctl() is here. * | argc | * |---------------| * | exec_path | * |:::::::::::::::| * | | * | Ssortingng area. | * | | * |---------------| <-- Top of stack. * : : * : : * \---------------/ 0xffffffff */ mib[0] = CTL_KERN; mib[1] = KERN_PROCARGS2; mib[2] = pid; size = (size_t)argmax; if (sysctl(mib, 3, procargs, &size, NULL, 0) == -1) { //goto ERROR_B; return @""; } memcpy(&nargs, procargs, sizeof(nargs)); cp = procargs + sizeof(nargs); /* Skip the saved exec_path. */ for (; cp < &procargs[size]; cp++) { if (*cp == '\0') { /* End of exec_path reached. */ break; } } if (cp == &procargs[size]) { //goto ERROR_B; return @""; } /* Skip trailing '\0' characters. */ for (; cp < &procargs[size]; cp++) { if (*cp != '\0') { /* Beginning of first argument reached. */ break; } } if (cp == &procargs[size]) { //goto ERROR_B; return @""; } /* Save where the argv[0] ssortingng starts. */ sp = cp; /* * Iterate through the '\0'-terminated ssortingngs and convert '\0' to ' ' * until a ssortingng is found that has a '=' character in it (or there are * no more ssortingngs in procargs). There is no way to deterministically * know where the command arguments end and the environment ssortingngs * start, which is why the '=' character is searched for as a heuristic. */ for (np = NULL; c < nargs && cp < &procargs[size]; cp++) { if (*cp == '\0') { c++; if (np != NULL) { /* Convert previous '\0'. */ *np = ' '; } else { /* *argv0len = cp - sp; */ } /* Note location of current '\0'. */ np = cp; if (!show_args) { /* * Don't convert '\0' characters to ' '. * However, we needed to know that the * command name was terminated, which we * now know. */ break; } } } /* * sp points to the beginning of the arguments/environment ssortingng, and * np should point to the '\0' terminator for the ssortingng. */ if (np == NULL || np == sp) { /* Empty or unterminated ssortingng. */ // goto ERROR_B; return @""; } /* Make a copy of the ssortingng. */ // printf("%s\n", sp); //path = sp; memset(path,0,1000); strcpy(path, sp); NSSsortingng *pathStr = [NSSsortingng ssortingngWithFormat:@"%s",path]; NSLog(@"%@",pathStr); // printf("%s\n", path); /* Clean up. */ free(procargs); return pathStr; ERROR_B: free(procargs); ERROR_A: printf("(%d)", pid); } 

La réponse de magicd et le commentaire de Victor avec le lien vers le file d'en-tête m'ont aidé à résoudre ce problème.

Je voulais append que vous devez append le nom MobileInstallation.framework aux "Frameworks et bibliothèques liés" dans Xcode. J'ai trouvé ce cadre ici:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/System/Library/PrivateFrameworks

Je peux confirmer que cela fonctionne sur un appareil non jailbreaké. L'App Store n'est pas un problème pour moi.

Voici le code que j'ai utilisé:

 NSDictionary *options = [NSDictionary dictionaryWithObject:@"Any" forKey:@"ApplicationType"]; NSDictionary *apps = (__bridge NSDictionary *) MobileInstallationLookup((__bridge CFDictionaryRef) options);