OGeek|极客世界-中国程序员成长平台

标题: c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:16
标题: c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域

我现在正在使用 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);


    }
}



Best Answer-推荐答案


我设法通过这样做添加了一个关联的域

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4