-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITCategory-NSBundle.m
38 lines (29 loc) · 1.45 KB
/
ITCategory-NSBundle.m
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
#import "ITCategory-NSBundle.h"
@implementation NSBundle (ITFoundationCategory)
+ (NSBundle *)bundleForFrameworkWithIdentifier:(NSString *)frameworkIdentifier {
NSMutableArray *frameworksPaths = [NSMutableArray array];
NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSAllDomainsMask,YES);
NSEnumerator *libraryEnumerator = [libraryPaths objectEnumerator];
NSString *libraryPath;
[frameworksPaths addObject:[[self mainBundle] privateFrameworksPath]];
[frameworksPaths addObject:[[self mainBundle] sharedFrameworksPath]];
while ((libraryPath = [libraryEnumerator nextObject])) {
[frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"Frameworks"]];
[frameworksPaths addObject:[libraryPath stringByAppendingPathComponent:@"PrivateFrameworks"]];
}
NSEnumerator *frameworksEnumerator = [frameworksPaths objectEnumerator];
NSString *frameworksPath;
while ((frameworksPath = [frameworksEnumerator nextObject])) {
NSArray *frameworkPaths = [NSBundle pathsForResourcesOfType:@"framework" inDirectory:frameworksPath];
NSEnumerator *frameworkEnumerator = [frameworkPaths objectEnumerator];
NSString *frameworkPath;
while ((frameworkPath = [frameworkEnumerator nextObject])) {
NSBundle *frameworkBundle = [NSBundle bundleWithPath:frameworkPath];
if (frameworkBundle && [[frameworkBundle bundleIdentifier] isEqualToString:frameworkIdentifier]) {
return frameworkBundle;
}
}
}
return nil;
}
@end