10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Unity5でXcodeproject Export時にplistやプロジェクト設定を変更する方法

Posted at
PostprocessBuildPlayer.cs
using System.IO;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;

public class PostprocessBuildPlayer {
	[PostProcessBuildAttribute]
	public static void OnPostprocessBuild(BuildTarget buildTarget, string path) {
		if (buildTarget == BuildTarget.iOS) {
			string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
			PBXProject project = new PBXProject();
			project.ReadFromFile(projectPath);

			string target = project.TargetGuidByName("Unity-iPhone");
			project.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
			project.WriteToFile(projectPath);

			var plistPath = Path.Combine(path, "Info.plist");
			var plist = new PlistDocument();
			plist.ReadFromFile(plistPath);
			plist.root.SetString("Privacy - Camera Usage Description", "カメラ使います。");
			plist.WriteToFile(plistPath);
		}
	}
}

##簡単に説明##

このコードで設定しているのは2つで、
1, BitCodeをNoに。
2, info.plistにiOS10からカメラアクセスで必須になったkey, valueを追加。

プロジェクト設定であれば、project.SetBuildProperty(target, "Key", "Value")
plistであれば、plist.root.SetString("Key", "Value")で追加という感じです。
targetとprojectPathに関しては適宜変更してください。

###配置場所###
PostprocessBuildPlayer.csはAssets/Editor/に格納してください。

10
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?