iOS获取已安装应用列表

1. /var/mobile/Applications/ 获取应用列表

 

    NSString *appDocDir = @"/var/mobile/Applications/"; //52844E32-3BDF-47DF-910E-3DCBB44324D6/";

    NSString *appDocDir1 = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] relativePath];

//    NSArray *contentdir = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];

 

    NSArray *contentOfFolder = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:appDocDir error:NULL];

    

//    NSDirectoryEnumerator* directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath: appDocDir];

    

 

    for (NSString *aPath in contentOfFolder) {

        NSLog(@"apath: %@", aPath);

        NSString * fullPath = [appDocDir stringByAppendingPathComponent:aPath];

        BOOL isDir;

        if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir] && !isDir)

        {

//            [fileList addObject: aPath];

            NSLog(@" -----   aPath:%@ ", aPath);

        }

 

 

 

 

2.  获取应用列表文件  com.apple.mobile.installation.plist

 

#pragma mark - Init  方法1

-(NSMutableArray *)desktopAppsFromDictionary:(NSDictionary *)dictionary

{

    NSMutableArray *desktopApps = [NSMutableArray array];

    

    for (NSString *appKey in dictionary)

    {

        [desktopApps addObject:appKey];

    }

    return desktopApps;

}

 

-(NSArray *)installedApp

{

    BOOL isDir = NO;

    static NSString* const installedAppListPath = @"/private/var/mobile/Library/Caches/com.apple.mobile.installation.plist";

 

    if([[NSFileManager defaultManager] fileExistsAtPath: installedAppListPath isDirectory: &isDir] && !isDir)

    {

        NSMutableDictionary *cacheDict = [NSDictionary dictionaryWithContentsOfFile: installedAppListPath];

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

        NSMutableArray *installedApp = [NSMutableArray arrayWithArray:[self desktopAppsFromDictionary:system]];

        

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

        [installedApp addObjectsFromArray:[self desktopAppsFromDictionary:user]];

        NSLog(@"installedApp :: %@",installedApp);

 

        return installedApp;

    }

    

    NSLog(@"can not find installed app plist");

    return nil;

}

#pragma mark - Init  //  方法2

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

}

 

 

 

 

 

 

 

 

    //

//#import "MobileInstallation.h"

#import "UIDevice+ProcessesAdditions.h"

 

    //越狱渠道

//    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:@"ApplicationType",@"Any",nil];

//    NSDictionary *apps = MobileInstallationLookup(options);

//    NSLog(@" %@", apps);

    

    // Example usage.  (公开)获取当前所有进程

    NSArray * processes = [[UIDevice currentDevice] runningProcesses];

    for (NSDictionary * dict in processes){

        NSLog(@"%@ - %@", [dict objectForKey:@"ProcessID"], [dict objectForKey:@"ProcessName"]);

    }

 

转载于:https://www.cnblogs.com/lee4519/p/4256632.html

### iOS 获取安装应用列表的方法 在 iOS 平台上,由于其严格的安全性和隐私保护机制,开发者无法直接获取设备上所有已安装应用程序列表。然而,在某些特定情况下,可以通过间接方式实现部分功能。 #### 使用 `canOpenURL` 方法检测特定应用是否存在 iOS 提供了一个 API——`UIApplication.shared.canOpenURL(url)`,可以用来检测当前设备是否能够打开指定 URL Scheme 的应用程序。如果返回值为 `true`,则表示该 URL Scheme 对应的应用可能已经安装;反之,则未安装。这种方法仅能用于检测支持公开 URL Schemes 的第三方应用,并不能全面列举所有已安装应用程序[^1]。 ```swift import UIKit func isAppInstalled(appScheme: String) -> Bool { let canOpen = UIApplication.shared.canOpenURL(URL(string: appScheme)! ) return canOpen } // 调用示例 let weChatInstalled = isAppInstalled(appScheme: "weixin://") ? "WeChat Installed" : "WeChat Not Found" print(weChatInstalled) ``` 需要注意的是,自 iOS 9 开始,Apple 引入了 `LSApplicationQueriesSchemes` 配置项限制可用的 URL schemes 列表长度,因此需要提前声明所要查询的服务提供商及其对应的 scheme 值于 Info.plist 文件中。 #### 私有库 LSApplicationWorkspace (越狱环境专用) 对于非官方渠道发布或者运行于越狱环境下开发应用而言,存在一种利用私有框架的方式访问更深层次的信息。例如调用 `objc_getClass("LSApplicationWorkspace")` 来尝试枚举系统中的所有 bundle identifiers 和其他元数据[^3]。但是这种方式违反 Apple Store 上架规定并可能导致被拒审风险极高,不推荐实际项目采用此方案除非确实处于特殊需求场景下才考虑使用。 综上所述,常规手段下我们只能借助有限数量预定义好的 url schemas 进行逐一排查确认目标 APP 是否存在于用户的 iDevice 当前状态之中而不可能得到完整的清单记录。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值