-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInstalledAppList.m
More file actions
48 lines (36 loc) · 1.66 KB
/
Copy pathInstalledAppList.m
File metadata and controls
48 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <objc/runtime.h>
#import "InstalledAppList.h"
@implementation InstalledAppList
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(getAll:(RCTResponseSenderBlock)callback)
{
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSString *sandBoxPath = [bundleRoot stringByDeletingLastPathComponent];
NSString *appFolderPath = [sandBoxPath stringByDeletingLastPathComponent];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:appFolderPath error:nil];
NSMutableArray *appNames = [[NSMutableArray alloc]init];
for(NSString *application in dirContents)
{
NSString *appPath = [appFolderPath stringByAppendingPathComponent:application];
NSArray *appcontents = [fm contentsOfDirectoryAtPath:appPath error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.app'"];
NSArray *onlyApps = [appcontents filteredArrayUsingPredicate:fltr];
NSString *infoPlistPath;
infoPlistPath = [NSString stringWithFormat:@"%@/%@/%@", appPath , onlyApps[0], @"Info.plist"];
NSDictionary *plistContent = [NSDictionary dictionaryWithContentsOfFile:infoPlistPath];
if (!plistContent) {
plistContent = @{};
}
if(onlyApps.count > 0) {
NSDictionary *item = @{
@"app": onlyApps[0],
@"appPath": appPath,
@"info": plistContent
};
[appNames addObject:item];
}
}
callback(@[appNames]);
}
@end