是否有可能获得有关iPhone上安装的所有应用程序的信息? [英] Is it possible to get information about all apps installed on iPhone?

查看:102
本文介绍了是否有可能获得有关iPhone上安装的所有应用程序的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以获取有关iPhone / iPod上已安装的所有应用的信息(应用图标,应用名称,应用位置)?

Is it possible to get the information (app icon, app name, app location) about all apps that have been installed on iPhone/iPod?

推荐答案

有一种方法可以检查是否安装了应用程序,但是,它确实违反了Sandbox规则,Apple *可能会拒绝您的应用程序使用它。但是之前App Store中提供的其他应用程序已经完成,所以可以随意尝试

there is a way to check if an application is installed or not, however, it does violate the Sandbox rules and Apple *may reject your app for using this. But it has been done before by other Apps that are available in the App Store, so feel free to try it

有时您可能想要检查是否安装了特定的应用程序在设备上,如果你使用自定义URL方案,需要安装其他一些应用程序(你可能只是灰显/禁用一些按钮)。不幸的是,Apple显然没有任何功能可以为你检查这个,所以我鞭打了一个。它不会枚举每个应用程序,而是使用MobileInstallation缓存,它始终与SpringBoard保持同步,并保存所有已安装应用程序的信息词典。尽管您并不应该访问缓存,但App Store应用程序可以读取它。这是我的代码至少与模拟器2.2.1完美配合:
代码:

Sometimes you may want to check if a specific app is installed on the device, in case you use custom URL schemes that require some other app to be installed (you could just gray out/disable some buttons then). Unfortunately, Apple apparently does not have any function that checks this for you, so I whipped one up. It does not enumerate every single app, instead it uses the MobileInstallation cache which is always up-to-date with SpringBoard and holds the Info dictionaries of all apps installed. Although you're not "supposed" to access the cache, it's readable by App Store apps. Here is my code which at least works perfectly fine with the Simulator 2.2.1: Code:

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

// Implementation

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;
}

以下是此示例,假设您的应用名为ownmadeapp并且是应用商店中的应用。
代码:

Here is an example of this, assuming that your app is named "yourselfmadeapp" and is an app in the app store. Code:

NSArray *bundles2Check = [NSArray arrayWithObjects: @"com.apple.mobilesafari", @"com.yourcompany.yourselfmadeapp", @"com.blahblah.nonexistent", nil];
for (NSString *identifier in bundles2Check)
    if (APCheckIfAppInstalled(identifier))
        NSLog(@"App installed: %@", identifier);
    else
        NSLog(@"App not installed: %@", identifier);

日志输出:
代码:

Log Output: Code:


2009-01-30 12:19:20.250
SomeApp [266:20b]安装的应用程序:
com.apple.mobilesafari 2009-01-30
12:19:20.254 SomeApp [266:20b] App
安装:
com.yourcompany.yourselfmadeapp
2009-01-30 12:19:20.260
SomeApp [266: 20b]应用程序未安装:
com.blahblah.nonexistent

2009-01-30 12:19:20.250 SomeApp[266:20b] App installed: com.apple.mobilesafari 2009-01-30 12:19:20.254 SomeApp[266:20b] App installed: com.yourcompany.yourselfmadeapp 2009-01-30 12:19:20.260 SomeApp[266:20b] App not installed: com.blahblah.nonexistent

在使用它之前试试这个,我想Apple改变了找到MobileInstallation.plist,如果你确实更改了它,请在实际设备上试用,而不是模拟器。祝你好运!

Try this out before using it, I think Apple changed where the MobileInstallation.plist is located and if you do change it, try it out on an actual device not the simulator. Good Luck!

http://www.iphonedevsdk.com/forum/iphone-sdk-development/37103-finding-out-what-apps-installed.html

PK

这篇关于是否有可能获得有关iPhone上安装的所有应用程序的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆