菜鸟教程小白 发表于 2022-12-11 19:16:33

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


                                            <p><p>我现在正在使用 Unity 开发一个 iOS 应用程序,我正在尝试设置关联的域,而无需在 xcode 上手动设置它。我相信我可以使用 <code>PostProcessBuild</code> 来实现这一点,但我想不通 </p>

<pre><code>public class AvametricIOSBuildPostProcessor
{

    static string[] associatedDomains;
   
    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, &#34;Unity-iPhone&#34;);
       associatedDomains = &#34;applinks:XXXXX&#34;;
       projectCapabilityManager.AddAssociatedDomains(associatedDomains);


    }
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我设法通过这样做添加了一个关联的域</p>

<pre><code>private static void OnProstProcessBuildIOS(string pathToBuiltProject)
{
    //This is the default path to the default pbxproj file. Yours might be different
    string projectPath = &#34;/Unity-iPhone.xcodeproj/project.pbxproj&#34;;
    //Default target name. Yours might be different
    string targetName = &#34;Unity-iPhone&#34;;
    //Set the entitlements file name to what you want but make sure it has this extension
    string entitlementsFileName = &#34;my_app.entitlements&#34;;

    var entitlements = new ProjectCapabilityManager(pathToBuiltProject + projectPath, entitlementsFileName, targetName);
    entitlements.AddAssociatedDomains(new string[] { &#34;applinks:myurl.com&#34; });
    //Apply
    entitlements.WriteToFile();
}
</code></pre>

<p>不要忘记提供 <strong>.pbxproj</strong> 文件的路径,而不是 <strong>.plist</strong> 或项目文件本身。
<br/> 确保您使用 <code>WriteToFile()</code> 应用您的更改。</p>

<p>关于 <a href="https://docs.unity3d.com/ScriptReference/iOS.Xcode.ProjectCapabilityManager.html" rel="noreferrer noopener nofollow">ProjectCapabilityManager</a> 的相关 Unity 文档和 <a href="https://docs.unity3d.com/ScriptReference/iOS.Xcode.ProjectCapabilityManager.AddAssociatedDomains.html" rel="noreferrer noopener nofollow">AddAssociatedDomains</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47233982/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47233982/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: c# - 如何使用 Unity 为 iOS 应用程序自动设置关联域