Skip to content

Commit 27b6b5c

Browse files
committed
Update XcodeCapabilities to use ProjectCapabilityManager
1 parent d996c5d commit 27b6b5c

File tree

1 file changed

+8
-58
lines changed

1 file changed

+8
-58
lines changed

scripts/gha/integration_testing/XcodeCapabilities.cs

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,13 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
7272
tempProject.ReadFromString(File.ReadAllText(projectPath));
7373
string targetId = GetMainTargetGUID(tempProject);
7474

75-
// This will look for an entitlements file in the unity project, and add it to the
76-
// PBX Project if found.
77-
AddEntitlements(tempProject, path, targetId);
75+
var capabilityManager = new ProjectCapabilityManager(projectPath, "dev.entitlements", null, targetId);
7876

7977
if (path.Contains("FirebaseMessaging")) {
80-
MakeChangesForMessaging(tempProject, path, targetId);
78+
MakeChangesForMessaging(capabilityManager);
8179
}
8280
if (path.Contains("FirebaseAuth")) {
83-
MakeChangesForAuth(tempProject, path, targetId);
81+
MakeChangesForAuth(capabilityManager);
8482
}
8583
// Bitcode is being deprecated by xcode, but Unity defaults to it on, so turn it off.
8684
tempProject.SetBuildProperty(targetId, "ENABLE_BITCODE", "NO");
@@ -89,67 +87,19 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string path)
8987
File.WriteAllText(projectPath, tempProject.WriteToString());
9088
}
9189

92-
static void AddEntitlements(object projectObj, string path, string targetId){
93-
var project = (PBXProject)projectObj;
94-
string[] entitlements = AssetDatabase.FindAssets("dev")
95-
.Select(AssetDatabase.GUIDToAssetPath)
96-
.Where(p => p.Contains("dev.entitlements"))
97-
.ToArray();
98-
// Only some APIs require entitlements so length 0 is okay
99-
if (entitlements.Length == 0) {
100-
Debug.Log("No entitlement file found.");
101-
return;
102-
}
103-
if (entitlements.Length > 1) {
104-
throw new System.InvalidOperationException("Multiple entitlements found.");
105-
}
106-
Debug.Log("Entitlement file found.");
107-
string entitlementPath = entitlements[0];
108-
109-
string entitlementFileName = Path.GetFileName(entitlementPath);
110-
string relativeDestination = Google.IOSResolver.PROJECT_NAME + "/" + entitlementFileName;
111-
FileUtil.CopyFileOrDirectory(entitlementPath, path + "/" + relativeDestination);
112-
project.AddFile(relativeDestination, entitlementFileName);
113-
// Not enough to add the entitlement: need to force the project to recognize it.
114-
project.AddBuildProperty(targetId, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
115-
Debug.Log("Added entitlement to xcode project.");
116-
}
117-
118-
static void MakeChangesForMessaging(object projectObj, string path, string targetId) {
119-
var project = (PBXProject)projectObj;
90+
static void MakeChangesForMessaging(ProjectCapabilityManager capabilityManager) {
12091
Debug.Log("Messaging testapp detected.");
121-
AddFramework(project, targetId, "UserNotifications.framework");
122-
EnableRemoteNotification(project, path, targetId);
92+
capabilityManager.AddPushNotifications(true);
93+
capabilityManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
12394
Debug.Log("Finished making messaging-specific changes.");
12495
}
12596

126-
static void MakeChangesForAuth(object projectObj, string path, string targetId) {
127-
var project = (PBXProject)projectObj;
97+
static void MakeChangesForAuth(ProjectCapabilityManager capabilityManager) {
12898
Debug.Log("Auth testapp detected.");
129-
AddFramework(project, targetId, "UserNotifications.framework");
99+
capabilityManager.AddPushNotifications(true);
130100
Debug.Log("Finished making auth-specific changes.");
131101
}
132102

133-
static void EnableRemoteNotification(object projectObj, string path, string targetId) {
134-
var project = (PBXProject)projectObj;
135-
Debug.Log("Adding remote-notification to UIBackgroundModes");
136-
var plist = new PlistDocument();
137-
string plistPath = path + "/Info.plist";
138-
plist.ReadFromString(File.ReadAllText(plistPath));
139-
PlistElementDict rootDict = plist.root;
140-
PlistElementArray backgroundModes = rootDict.CreateArray("UIBackgroundModes");
141-
backgroundModes.AddString("remote-notification");
142-
File.WriteAllText(plistPath, plist.WriteToString());
143-
Debug.Log("Finished adding remote-notification.");
144-
}
145-
146-
static void AddFramework(object projectObj, string targetId, string framework) {
147-
var project = (PBXProject)projectObj;
148-
Debug.LogFormat("Adding framework to xcode project: {0}.", framework);
149-
project.AddFrameworkToProject(targetId, framework, false);
150-
Debug.Log("Finished adding framework.");
151-
}
152-
153103
static string GetMainTargetGUID(object pbxProjectObj) {
154104
var pbxProject = (PBXProject)pbxProjectObj;
155105
// In 2019.3 Unity changed this API without an automated update path via the api-updater.

0 commit comments

Comments
 (0)