2011-12-27 7 views
7

पर स्थापित अनुप्रयोगों की सूची प्राप्त करें मेरे पास एक ऐसा एप्लिकेशन है जिसे डिवाइस पर स्थापित (अन्य, शायद तीसरे पक्ष) अनुप्रयोगों की सूची प्राप्त करने की आवश्यकता है। यह कैसे किया जा सकता है? या यह बिल्कुल किया जा सकता है?आईफोन उद्देश्य-सी

+2

यह डुप्लिकेट एक, कृपया निम्न thread- उल्लेख है http://stackoverflow.com/questions/4614114/get-list-of-installed-apps- ऑन-आईफोन – rishi

+0

इस चाल को करने के लिए किसी तीसरे पक्ष के पुस्तकालय मौजूद हैं? – Oleg

+0

धन्यवाद @ ऋषि। मैंने यह खो दिया। कृपया अपनी टिप्पणी के साथ मेरे प्रश्न का उत्तर दें। – Oleg

उत्तर

3

मुझे संदेह है कि कुछ उपलब्ध है (यदि कुछ आईफोन जेलब्रैक हो गया है और उपयोगकर्ता फ़ाइल सिस्टम तक पहुंच सकता है, तो यह संभव होगा, लेकिन मुझे इसके बारे में पता नहीं है।), लेकिन आप निम्नलिखित link का उपयोग कर सकते हैं और इसकी सहायता से जांच सकते हैं कि सभी ऐप क्या मौजूद हैं और आप अपनी कुछ ज़रूरतों के साथ अनुकूलित कर सकते हैं।

5

वहाँ सेब से कोई सार्वजनिक एपीआई (आइपॉड टच/iPhone/iPad) iOS डिवाइस से ऐसे सूची प्राप्त करने में है

6
-(NSArray *) installedApps 
{ 
    BOOL isDir enter code here= NO; 
    NSDictionary *cacheDienter code herect; 
    NSDictionary *user; 
    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist"; 
    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName]; 
    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: 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; 
} 

इसमें आपके द्वारा इंस्टॉल ऐप्लिकेशन के नाम पर की सरणी निजी एपीआई का उपयोग कर दे देंगे

+2

डिवाइस पर आईओएस 6 के तहत काम नहीं करता है। फ़ाइल मौजूद नहीं है। वास्तव में –

16

आप सेब निजी ढांचे "MobileInstallationInstall" के माध्यम से अपने सभी ऐप्स स्कैन कर सकते हैं।

विधि नीचे की तरह है:

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

यह केवल जेबी उपकरणों में इस्तेमाल किया जा सकता है।

+1

। इसका इस्तेमाल जेल डिवाइस पर भी किया जा सकता है। हालांकि, आप इस कोड के साथ ऐपस्टोर में ऐप नहीं प्राप्त कर सकते हैं, क्योंकि यह निजी एपीआई है। –

+0

मैं MobileInstallationInstall के लिए शीर्षलेख कैसे प्राप्त कर सकता हूं? – EwyynTomato

+0

@EwyynTomato: शीर्षलेख यहां उदाहरण के रूप में पाए जा सकते हैं: https://github.com/Cykey/ios-reversed-headers/blob/master/MobileInstallation/MobileInstallation.h –

2

यह WONT इंस्टॉल किए गए ऐप्स की सूची देता है लेकिन आप इस कोड द्वारा पृष्ठभूमि और उनके संबंधित प्रक्रियाओं में चल रहे अनुप्रयोगों की सूची प्राप्त कर सकते हैं। viewDidLoad से

कॉल -

[self printProcessInfo]; 

-(NSMutableString*) 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 = [[NSMutableString alloc] init]; 
NSMutableString *localStr = [[NSMutableString 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 = [NSString stringWithFormat:@"%@,\nPID:-%5d,\tPROCESS_NAME:-%s\n",localStr,(int)procs[i].kp_proc.p_pid, procs[i].kp_proc.p_comm ]; 
     NSString *pathStr = [self print_argv_of_pid:(int)procs[i].kp_proc.p_pid]; 
     //NSString *pathStr = print_argv_of_pid:(((int)procs[i].kp_proc.p_pid)); 
     localStr = [NSString stringWithFormat:@"%@,\n%@\n",localStr,pathStr ]; 
    // [self getAttributesOfProcess]; 
     //printf("%s",path); 


} 
NSLog(@"%@",lists); 

free(procs); 
return localStr; 
//return (0); 
} 



-(NSString*) 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  | 
    * |:::::::::::::::| 
    * |    | 
    * | String 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] string starts. */ 
sp = cp; 

/* 
    * Iterate through the '\0'-terminated strings and convert '\0' to ' ' 
    * until a string is found that has a '=' character in it (or there are 
    * no more strings in procargs). There is no way to deterministically 
    * know where the command arguments end and the environment strings 
    * 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 string, and 
    * np should point to the '\0' terminator for the string. 
    */ 
if (np == NULL || np == sp) { 
     /* Empty or unterminated string. */ 
     // goto ERROR_B; 
     return @""; 
} 

/* Make a copy of the string. */ 
// printf("%s\n", sp); 
//path = sp; 
memset(path,0,1000); 
strcpy(path, sp); 
NSString *pathStr = [NSString stringWithFormat:@"%s",path]; 
NSLog(@"%@",pathStr); 
// printf("%s\n", path); 
/* Clean up. */ 
free(procargs); 
return pathStr; 

ERROR_B: 
free(procargs); 
ERROR_A: 
printf("(%d)", pid); 

} 
0

तो जादूगर का जवाब और हेडर फ़ाइल के लिंक के साथ विक्टर की टिप्पणी ने मुझे इसे हल करने में मदद की।

मैं यह जोड़ना चाहता था कि आपको Xcode में "लिंक्ड फ्रेमवर्क और लाइब्रेरीज़" में MobileInstallation.framework जोड़ना होगा।

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

मैं पुष्टि कर सकता है कि: मैं उस ढांचे यहां पाया यह गैर-जेलब्रोकन डिवाइस पर काम करता है। ऐप स्टोर मेरे लिए चिंता नहीं है।

यहाँ कोड मैं प्रयोग किया जाता है:

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