c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域

标签 c# ios unity3d ios-universal-links

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

相关文章:

c# - 使用语句和关闭方法

c# - 在 EF Core 2.0 中使用 DataTable 作为表值参数

ios - ./configure 参数为 iOS 构建 C 库

iphone - 购买时重复方法

ios - 无论语言环境如何,如何强制 Swift Decimal Pad 使用点而不是逗号?

unity3d - 'Master' : implicit truncation of vector type 中的着色器警告

unity3d - 构建 .exe(UNITY) 时相机处于不同位置

c# - 属性网格 > 如何刷新主属性

c# - 扩展方法中的协程

c# - httpErrors web.config 部分阻止调试