@@ -16,6 +16,10 @@ + (instancetype)projectForKeyWindow
1616 id workspace = [VVWorkspaceManager workspaceForKeyWindow ];
1717
1818 id contextManager = [workspace valueForKey: @" _runContextManager" ];
19+ // id activeScheme = [contextManager valueForKey:@"_activeRunContext"];
20+ // NSString *activeSchemeName = [activeScheme valueForKey:@"name"];
21+ // id activeSchemeIdentifier = [activeScheme valueForKey:@"schemeIdentifier"];
22+
1923 for (id scheme in[contextManager valueForKey: @" runContexts" ]) {
2024 NSString *schemeName = [scheme valueForKey: @" name" ];
2125 if (![schemeName hasPrefix: @" Pods-" ]) {
@@ -34,8 +38,18 @@ - (id)initWithName:(NSString *)name
3438 _projectName = name;
3539 _directoryPath = path;
3640
37- // FIXME: 此处应从工程配置文件中,获取info.plist文件名称. 目前使用默认名称查找
38- NSString *infoPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ /%@ -Info.plist" , _projectName, _projectName]];
41+
42+ NSString *pbxprojPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ .xcodeproj/project.pbxproj" ,name]];
43+ _pbxprojDictionary = [NSDictionary dictionaryWithContentsOfFile: pbxprojPath];
44+
45+
46+
47+ _organizeationName = [self getOrganizeationName ];
48+ NSString *infoplistName = [self infoplistNameWithAtScheme: name];
49+
50+
51+ NSString *infoPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ " , infoplistName]];
52+
3953
4054 _infoDictionary = [NSDictionary dictionaryWithContentsOfFile: infoPath];
4155
@@ -45,4 +59,58 @@ - (id)initWithName:(NSString *)name
4559 return self;
4660}
4761
62+ -(NSString *)getOrganizeationName {
63+ NSDictionary *objects = [_pbxprojDictionary objectForKey: @" objects" ];
64+ NSString *rootObjectId = [_pbxprojDictionary objectForKey: @" rootObject" ];
65+
66+ NSDictionary *pbxProjectDic = [objects objectForKey: rootObjectId];
67+ NSDictionary *attributes = [pbxProjectDic objectForKey: @" attributes" ];
68+ NSString *organizeationName = [attributes objectForKey: @" ORGANIZATIONNAME" ];
69+ return organizeationName;
70+ }
71+
72+ -(NSString *)infoplistNameWithAtScheme : (NSString *)currentSchemeName {
73+ NSDictionary *objects = [_pbxprojDictionary objectForKey: @" objects" ];
74+ NSString *rootObjectId = [_pbxprojDictionary objectForKey: @" rootObject" ];
75+
76+ NSDictionary *pbxProjectDic = [objects objectForKey: rootObjectId];
77+ NSArray *targetIds = [pbxProjectDic objectForKey: @" targets" ];
78+ NSString *currentTargetId;
79+ for (NSString *targetId in targetIds) {
80+ NSDictionary *targetDic = [objects objectForKey: targetId];
81+ NSString *targetName = [targetDic objectForKey: @" name" ];
82+ if ([targetName isEqualToString: currentSchemeName]) {
83+ currentTargetId = targetId;
84+ break ;
85+ }
86+ }
87+ if (!currentTargetId) {
88+ currentTargetId = [targetIds firstObject ];
89+ }
90+
91+ NSDictionary *targetDic = [objects objectForKey: currentTargetId];
92+ NSString *buildConfigurationListId = [targetDic objectForKey: @" buildConfigurationList" ];
93+
94+ NSDictionary *buildConfigurationListDic = [objects objectForKey: buildConfigurationListId];
95+ NSArray *buildConfigurationIds = [buildConfigurationListDic objectForKey: @" buildConfigurations" ];
96+
97+ NSString *debugBuildConfigurationId;
98+ for (NSString *buildConfigurationId in buildConfigurationIds) {
99+ NSDictionary *buildConfigurationDic = [objects objectForKey: buildConfigurationId];
100+ NSString *name = [buildConfigurationDic objectForKey: @" name" ];
101+ if ([name isEqualToString: @" Debug" ]) {
102+ debugBuildConfigurationId = buildConfigurationId;
103+ break ;
104+ }
105+ }
106+ if (!debugBuildConfigurationId) {
107+ debugBuildConfigurationId = [buildConfigurationIds firstObject ];
108+ }
109+
110+ NSDictionary *buildConfigurationDic = [objects objectForKey: debugBuildConfigurationId];
111+ NSDictionary *buildSettings = [buildConfigurationDic objectForKey: @" buildSettings" ];
112+ NSString *infoplistName = [buildSettings objectForKey: @" INFOPLIST_FILE" ];
113+ return infoplistName;
114+ }
115+
48116@end
0 commit comments