我现在正在使用 Unity 开发一个 iOS 应用程序,我正在尝试设置关联的域,而无需在 xcode 上手动设置它。我相信我可以使用 PostProcessBuild
来实现这一点,但我想不通
public class AvametricIOSBuildPostProcessor
{
static string[] associatedDomains;
[PostProcessBuild]
public static void OnPostprocessBuild (BuildTarget target, string pathToBuiltProject)
{
if (target == BuildTarget.iOS)
OnPostprocessBuildIOS (pathToBuiltProject);
}
private static void OnPostprocessBuildIOS (string pathToBuiltProject)
{
var projectCapabilityManager = new ProjectCapabilityManager(plistPath, plistPath, "Unity-iPhone");
associatedDomains[0] = "applinks:XXXXX";
projectCapabilityManager.AddAssociatedDomains(associatedDomains);
}
}
我设法通过这样做添加了一个关联的域
private static void OnProstProcessBuildIOS(string pathToBuiltProject)
{
//This is the default path to the default pbxproj file. Yours might be different
string projectPath = "/Unity-iPhone.xcodeproj/project.pbxproj";
//Default target name. Yours might be different
string targetName = "Unity-iPhone";
//Set the entitlements file name to what you want but make sure it has this extension
string entitlementsFileName = "my_app.entitlements";
var entitlements = new ProjectCapabilityManager(pathToBuiltProject + projectPath, entitlementsFileName, targetName);
entitlements.AddAssociatedDomains(new string[] { "applinks:myurl.com" });
//Apply
entitlements.WriteToFile();
}
不要忘记提供 .pbxproj 文件的路径,而不是 .plist 或项目文件本身。
确保您使用 WriteToFile()
应用您的更改。
关于 ProjectCapabilityManager 的相关 Unity 文档和 AddAssociatedDomains
关于c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47233982/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |