2020.10.02 Unity 輸出檔案在 iOS 上如果跟其他 App 共用,必須在 Build 至 Xcode 專案時編輯Info.plist 按右鍵 Open As => Source Code ,如圖:
在中間加入兩個 Key 並存檔:
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
這樣在輸出到 iOS 實機上就能用 檔案 App 存取檔案。
另一個自動更改 Info.plist 方法是將以下檔案放在Assets/Editor/下檔名為 BuildPostProcessor.cs。
// filename BuildPostProcessor.cs
// put it in a folder Assets/Editor/
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class BuildPostProcessor
{
[PostProcessBuild]
public static void ChangeXcodePlist(BuildTarget buildTarget, string path)
{
if (buildTarget == BuildTarget.iOS)
{
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(plistPath);
PlistElementDict rootDict = plist.root;
//Debug.Log(">> Automation, plist ... <<");
// example of changing a value:
// rootDict.SetString("CFBundleVersion", "6.6.6");
// example of adding a boolean key...
// < key > ITSAppUsesNonExemptEncryption </ key > < false />
rootDict.SetBoolean("UIFileSharingEnabled", true);
rootDict.SetBoolean("LSSupportsOpeningDocumentsInPlace", true);
File.WriteAllText(plistPath, plist.WriteToString());
}
}
}
沒有留言:
張貼留言