Skip to content

Commit 9627093

Browse files
committed
Add a new param to GetXcodeTargetGuids()
Add a new param to GetXcodeTargetGuids() to return guids from all targets in Unity 2019.3+. By default, GetXcodeTargetGuids() only returns guids of the target which includes Unity and third-party libraries. It is `Unity-iPhone` for Unity 2019.2 or below or `UnityFramework` for Unity 2019.3+. Introduce a new param "includeAllTargets" to return guids of all targets, excluding test targets, when multiple Xcode project target is supported from Unity 2019.3+. This is useful when we need to add target membership to all targets for special cases. For example, adding `Google-Services.plist` to all targets in order to support the case when the user's project has dependency on Swift framework, such as Facebook SDK. Bug: 174515725 Change-Id: I2374800cefc21d79cf9a7fb6f66a39f0acbbdade
1 parent e195764 commit 9627093

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

source/IOSResolver/src/IOSResolver.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,15 +1683,34 @@ public static IEnumerable<string> XcodeTargetNames {
16831683
/// <param name="xcodeProject">UnityEditor.iOS.Xcode.PBXProject project to query.</param>
16841684
/// <returns>List of target GUIDs.</returns>
16851685
public static IEnumerable<string> GetXcodeTargetGuids(object xcodeProject) {
1686+
return GetXcodeTargetGuids(xcodeProject, includeAllTargets: false);
1687+
}
1688+
1689+
/// <summary>
1690+
/// Get Xcode target GUIDs using a method that works across all Unity versions.
1691+
/// </summary>
1692+
/// <param name="xcodeProject">UnityEditor.iOS.Xcode.PBXProject project to query.</param>
1693+
/// <param name="includeAllTargets">If true, if multiple xcode project targets is supported, ex.
1694+
/// Unity 2019.3+, returns both guids of 'UnityFramework' and the main target 'Unity-iPhone`.
1695+
/// Otherwise, only return the guid of the target which contains Unity libraries. For Unity
1696+
/// 2019.2 or below, it is the guid of `Unity-iPhone`; for Unity 2019.3+, it is the guid of
1697+
/// `UnityFramework`.
1698+
/// </param>
1699+
/// <returns>List of target GUIDs.</returns>
1700+
public static IEnumerable<string> GetXcodeTargetGuids(object xcodeProject,
1701+
bool includeAllTargets) {
16861702
var project = (UnityEditor.iOS.Xcode.PBXProject)xcodeProject;
16871703
var targets = new List<string>();
16881704
if (MultipleXcodeTargetsSupported) {
16891705
// In Unity 2019.3+ TargetGuidByName will throw an exception if the Unity-iPhone target
16901706
// is requested so we need to use instance methods to fetch the GUIDs of each target.
16911707
// NOTE: The test target is not exposed.
16921708
try {
1693-
foreach (var guidMethod in
1694-
new[] { "GetUnityFrameworkTargetGuid" }) {
1709+
var guidMethods = new List<string>() {"GetUnityFrameworkTargetGuid"};
1710+
if (includeAllTargets) {
1711+
guidMethods.Add("GetUnityMainTargetGuid");
1712+
}
1713+
foreach (var guidMethod in guidMethods) {
16951714
targets.Add((string)VersionHandler.InvokeInstanceMethod(project, guidMethod,
16961715
null));
16971716
}

0 commit comments

Comments
 (0)