简体   繁体   English

在 iphone 上查找已安装的应用程序列表

[英]Finding list of installed apps on iphone

Is it possible to programatically find out name of all apps installed on my iOS device ?是否可以通过编程方式找出我的 iOS 设备上安装的所有应用程序的名称? Is there any API available for same ?是否有相同的 API 可用?

Thanks for the help感谢您的帮助

不,由于沙盒环境,iOS 应用程序无法访问其他应用程序的信息/关于其他应用程序的信息。

Yes it is possible to get list of all installed app是的,可以获取所有已安装应用程序的列表

-(void) allInstalledApp
{    
    NSDictionary *cacheDict;

    NSDictionary *user;

    static NSString *const cacheFileName = @"com.apple.mobile.installation.plist";

    NSString *relativeCachePath = [[@"Library" stringByAppendingPathComponent: @"Caches"] stringByAppendingPathComponent: cacheFileName];

    NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent: @"../.."] stringByAppendingPathComponent: relativeCachePath];

    cacheDict    = [NSDictionary dictionaryWithContentsOfFile: path];

    user = [cacheDict objectForKey: @"User"];

    NSDictionary *systemApp=[cacheDict objectForKey:@"System"];
}   

systemApp Dictionary contains the list of all system related app and user Dictionary contains other app information. systemApp Dictionary包含所有系统相关应用程序的列表, user Dictionary包含其他应用程序信息。

There are ways to do this without a jailbroken device and not get your app rejected.有很多方法可以在没有越狱设备的情况下做到这一点,并且不会让您的应用程序被拒绝。
1. get a list of currently running processes see this SO answer. 1. 获取当前正在运行的进程列表,请参阅SO 答案。 You will need to translate from process name to app name.您需要将进程名称转换为应用程序名称。
2. Check to see if any apps have registered a unique URL scheme with UIApplicationDelegate canOpenURL. 2. 检查是否有任何应用程序使用 UIApplicationDelegate canOpenURL 注册了唯一的 URL 方案。 There are a few sites cataloging known url schemes, this is the best one.有几个站点对已知的 url 方案进行编目,是最好的一个。

If an app is not currently running and does not register a custom url scheme then it will not be detected by these methods.如果应用程序当前未运行且未注册自定义 url 方案,则这些方法不会检测到它。 I am interested in hearing a method that will be allowed in the app store that works better than this.我有兴趣听到一种在应用程序商店中允许的比这更好的方法。

Not from the device.不是来自设备。 However, from the desktop you could peek into the iTunes library.但是,您可以从桌面查看 iTunes 资料库。

try this, it will work even with non-jailbroken devices:试试这个,它甚至可以在非越狱设备上工作:

#include <objc/runtime.h>
Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
SEL selector=NSSelectorFromString(@"defaultWorkspace");

NSObject* workspace = [LSApplicationWorkspace_class performSelector:selector];

SEL selectorALL = NSSelectorFromString(@"allApplications");

NSLog(@"apps: %@", [workspace performSelector:selectorALL]);//will give you all **Bundle IDS** of user's all installed apps

您可以通过使用canOpenURL方法检查应用程序是否已安装或检查后台进程并将它们与您感兴趣的应用程序名称进行匹配来实现。

You can use runtime objective c to get the list of all installed apps.您可以使用运行时目标 c 来获取所有已安装应用程序的列表。 It will give you an array of LSApplicationProxy objects.它将为您提供一组LSApplicationProxy对象。

Following is a code snippet that prints Name of all applications installed in your device.以下是打印设备中安装的所有应用程序名称的代码片段。

Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
NSObject* workspace = [LSApplicationWorkspace_class performSelector:NSSelectorFromString(@"defaultWorkspace")];
NSMutableArray *array = [workspace performSelector:NSSelectorFromString(@"allApplications")];

NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
for (id lsApplicationProxy in array) {
    if(nil != [lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]){
        [mutableArray addObject:[lsApplicationProxy performSelector:NSSelectorFromString(@"itemName")]];
    }
}
NSLog(@"********* Applications List ************* : \n %@",mutableArray);

Don't forget to include <objc/runtime.h> .不要忘记包含<objc/runtime.h>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM