2013-10-31 46 views
0

我需要知道在沒有越獄的情況下iDevice上安裝了哪些應用程序。我tryed不同methodes,這似乎是最好的,但如果您提交的應用程序批准蘋果在iOS 7如何在沒有越獄的情況下獲取所有已安裝應用程序的軟件包ID

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier) 
{ 
    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist"; 
    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName]; 
    NSDictionary *cacheDict = nil; 
    NSString *path = nil; 
    // Loop through all possible paths the cache could be in 
    for (short i = 0; 1; i++) 
    { 

     switch (i) { 
      case 0: // Jailbroken apps will find the cache here; their home directory is /var/mobile 
       path = [NSHomeDirectory() stringByAppendingPathComponent: relativeCachePath]; 
       break; 
      case 1: // App Store apps and Simulator will find the cache here; home (/var/mobile/) is 2 directories above sandbox folder 
       path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath]; 
       break; 
      case 2: // If the app is anywhere else, default to hardcoded /var/mobile/ 
       path = [@"/var/mobile" stringByAppendingPathComponent: relativeCachePath]; 
       break; 
      default: // Cache not found (loop not broken) 
       return NO; 
      break; } 

     BOOL isDir = NO; 
     if ([[NSFileManager defaultManager] fileExistsAtPath: path isDirectory: &isDir] && !isDir) // Ensure that file exists 
      cacheDict = [NSDictionary dictionaryWithContentsOfFile: path]; 

     if (cacheDict) // If cache is loaded, then break the loop. If the loop is not "broken," it will return NO later (default: case) 
      break; 
    } 

    NSDictionary *system = [cacheDict objectForKey: @"System"]; // First check all system (jailbroken) apps 
    if ([system objectForKey: bundleIdentifier]) return YES; 
    NSDictionary *user = [cacheDict objectForKey: @"User"]; // Then all the user (App Store /var/mobile/Applications) apps 
    if ([user objectForKey: bundleIdentifier]) return YES; 

    // If nothing returned YES already, we'll return NO now 
    return NO; 
} 

BOOL APCheckIfAppInstalled(NSString *bundleIdentifier); // Bundle identifier (eg. com.apple.mobilesafari) used to track apps 

    NSArray *bundles2Check = [NSArray arrayWithObjects: @"com.apple.mobilesafari", @"com.my.application", @"com.blahblah.nonexistent", nil]; 

    for (NSString *identifier in bundles2Check) 

     if (APCheckIfAppInstalled(identifier)) 

      NSLog(@"App installed: %@", identifier); 

     else 

      NSLog(@"App not installed: %@", identifier); 
+0

嗨大衛G.你有解決方案嗎? – HDNZ

+0

不,對不起。我還沒有答案 –

回答

0

所有這些方法都不會工作將被拒絕。而且所有的應用程序都安裝在他們自己的沙箱中,這意味着他們不能在自己的應用程序之外做任何事情。因此,如果沒有越獄,使用記錄的API(您沒有權限訪問NSHomeDirectory())並考慮沙盒,則無法執行此操作。

+0

我不想將應用程序提交到AppStore –

相關問題