-
|
The readme says that for Game Center cloud saves, you must set up the XCode project in certain ways: Game Center and iCloud capabilities, iCloud Documents checkbox, iCloud container config. Do you do this by hand for every clean Unity iOS build, or is there a way to persist it? Thanks again. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
The way to "persist" this kind of thing is using post-build scripts that edit the generated XCode project. You can use Unity's ProjectCapabilityManager API to setup the generated XCode project, the documentation has very good examples for both Game Center and iCloud. |
Beta Was this translation helpful? Give feedback.
-
|
I seem to have it working and figured I'd post my code in case it helps someone. Assets/Editor/AddAppleCapabilities.cs using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;
public class AddAppleCapabilities
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget,
string pathToBuiltProject)
{
if (buildTarget is not (BuildTarget.StandaloneOSX or
BuildTarget.iOS or
BuildTarget.tvOS or
BuildTarget.VisionOS))
return;
var projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
var pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);
var mainTargetGuid = pbxProject.GetUnityMainTargetGuid();
var entitlementsFile =
pbxProject.GetBuildPropertyForAnyConfig(mainTargetGuid,
"CODE_SIGN_ENTITLEMENTS") ??
$"{Application.productName}.entitlements";
var capabilityManager =
new ProjectCapabilityManager(projectPath,
entitlementsFile,
targetGuid: mainTargetGuid);
capabilityManager.AddGameCenter();
capabilityManager.AddiCloud(enableKeyValueStorage: false,
enableiCloudDocument: true,
enablecloudKit: false,
addDefaultContainers: true,
customContainers: null);
capabilityManager.WriteToFile();
}
}I was not able to add a "custom" container without the default container also being added, even with |
Beta Was this translation helpful? Give feedback.
The way to "persist" this kind of thing is using post-build scripts that edit the generated XCode project. You can use Unity's ProjectCapabilityManager API to setup the generated XCode project, the documentation has very good examples for both Game Center and iCloud.