@@ -16,6 +16,7 @@ + (instancetype)projectForKeyWindow
1616 id workspace = [VVWorkspaceManager workspaceForKeyWindow ];
1717
1818 id contextManager = [workspace valueForKey: @" _runContextManager" ];
19+
1920 for (id scheme in[contextManager valueForKey: @" runContexts" ]) {
2021 NSString *schemeName = [scheme valueForKey: @" name" ];
2122 if (![schemeName hasPrefix: @" Pods-" ]) {
@@ -34,8 +35,17 @@ - (id)initWithName:(NSString *)name
3435 _projectName = name;
3536 _directoryPath = path;
3637
37- // FIXME: 此处应从工程配置文件中,获取info.plist文件名称. 目前使用默认名称查找
38- NSString *infoPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ /%@ -Info.plist" , _projectName, _projectName]];
38+
39+ NSString *pbxprojPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ .xcodeproj/project.pbxproj" ,name]];
40+ _pbxprojDictionary = [NSDictionary dictionaryWithContentsOfFile: pbxprojPath];
41+
42+
43+
44+ _organizeationName = [self getOrganizeationName ];
45+ NSString *infoplistName = [self infoplistNameWithAtScheme: name];
46+
47+ NSString *infoPath = [path stringByAppendingPathComponent: [NSString stringWithFormat: @" %@ " , infoplistName]];
48+
3949
4050 _infoDictionary = [NSDictionary dictionaryWithContentsOfFile: infoPath];
4151
@@ -45,4 +55,58 @@ - (id)initWithName:(NSString *)name
4555 return self;
4656}
4757
58+ -(NSString *)getOrganizeationName {
59+ NSDictionary *objects = [_pbxprojDictionary objectForKey: @" objects" ];
60+ NSString *rootObjectId = [_pbxprojDictionary objectForKey: @" rootObject" ];
61+
62+ NSDictionary *pbxProjectDic = [objects objectForKey: rootObjectId];
63+ NSDictionary *attributes = [pbxProjectDic objectForKey: @" attributes" ];
64+ NSString *organizeationName = [attributes objectForKey: @" ORGANIZATIONNAME" ];
65+ return organizeationName;
66+ }
67+
68+ -(NSString *)infoplistNameWithAtScheme : (NSString *)currentSchemeName {
69+ NSDictionary *objects = [_pbxprojDictionary objectForKey: @" objects" ];
70+ NSString *rootObjectId = [_pbxprojDictionary objectForKey: @" rootObject" ];
71+
72+ NSDictionary *pbxProjectDic = [objects objectForKey: rootObjectId];
73+ NSArray *targetIds = [pbxProjectDic objectForKey: @" targets" ];
74+ NSString *currentTargetId;
75+ for (NSString *targetId in targetIds) {
76+ NSDictionary *targetDic = [objects objectForKey: targetId];
77+ NSString *targetName = [targetDic objectForKey: @" name" ];
78+ if ([targetName isEqualToString: currentSchemeName]) {
79+ currentTargetId = targetId;
80+ break ;
81+ }
82+ }
83+ if (!currentTargetId) {
84+ currentTargetId = [targetIds firstObject ];
85+ }
86+
87+ NSDictionary *targetDic = [objects objectForKey: currentTargetId];
88+ NSString *buildConfigurationListId = [targetDic objectForKey: @" buildConfigurationList" ];
89+
90+ NSDictionary *buildConfigurationListDic = [objects objectForKey: buildConfigurationListId];
91+ NSArray *buildConfigurationIds = [buildConfigurationListDic objectForKey: @" buildConfigurations" ];
92+
93+ NSString *debugBuildConfigurationId;
94+ for (NSString *buildConfigurationId in buildConfigurationIds) {
95+ NSDictionary *buildConfigurationDic = [objects objectForKey: buildConfigurationId];
96+ NSString *name = [buildConfigurationDic objectForKey: @" name" ];
97+ if ([name isEqualToString: @" Debug" ]) {
98+ debugBuildConfigurationId = buildConfigurationId;
99+ break ;
100+ }
101+ }
102+ if (!debugBuildConfigurationId) {
103+ debugBuildConfigurationId = [buildConfigurationIds firstObject ];
104+ }
105+
106+ NSDictionary *buildConfigurationDic = [objects objectForKey: debugBuildConfigurationId];
107+ NSDictionary *buildSettings = [buildConfigurationDic objectForKey: @" buildSettings" ];
108+ NSString *infoplistName = [buildSettings objectForKey: @" INFOPLIST_FILE" ];
109+ return infoplistName;
110+ }
111+
48112@end
0 commit comments