12
12

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.

Unity+VuforiaがiPhone6+でクラッシュするので、自動でInfo.plistを書き換えるようにしてみたメモ

Last updated at Posted at 2014-10-06

はじめに

前回書いた記事「Unity+VuforiaがiPhone6+でクラッシュする」では、手動で対処していたInfo.plistの修正を自動にしてみました。

コード

自動で書き換えるためには、以下のコードをAssets/Editorフォルダにおいてください。
Info.plistへのパスを決め打ちにしていますので、各自の環境にあわせて適当に書き換えてください。

なお、以下のコードは”エンジニア Blog”さんの「Unity iOSビルド時にinfo.plistに設定を自動で登録する」という記事のコードに追加・修正する部分のみのせています。最初に該当する記事のコードを参照してください。

PlistMod.cs(変更部分のみ)
using UnityEngine;
using UnityEditor;            // 追加
using UnityEditor.Callbacks;  // 追加
using System.IO;
using System.Xml;

public class PlistMod {
	//
	// (省略)
	//


	// 引数を若干変更しています。
	public static void UpdatePlist(string path, string key, string val) {
		//
		// (省略)
		//

		
		// 1. 設定値

		// 以下の6行を修正
		if(!HasKey (dict, key)) {
			AddChildElement (doc, dict, "key", key);
			AddChildElement (doc, dict, "string", val);
		} else {
			UpdateKeyValue (dict, key, "string", val);
		}
		
		//
		// (省略)
		//
	}


	// 関数OnPostprocessBuildを追加。
	// Assets/Editorフォルダに、このスクリプトをいれておくと自動でInfo.plistを書き換える。
	// UIInterfaceOrientationは次の4つの値をとりうる。
	//   UIInterfaceOrientationPortrait
	//   UIInterfaceOrientationPortraitUpsideDown
	//   UIInterfaceOrientationLandscapeLeft
	//   UIInterfaceOrientationLandscapeRight
	[PostProcessBuild]
	public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
		// "iOS"のところは、Info.plistがあるフォルダへのパス(Xcodeプロジェクトを保存したパス)を指定する。
		UpdatePlist("iOS", "UIInterfaceOrientation", "UIInterfaceOrientationPortrait");
	}
}

参考

Unity iOSビルド時にinfo.plistに設定を自動で登録する
Unityビルド後に処理を実行させる方法

12
12
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
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?