質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

2回答

10452閲覧

Unityから自動でPush NotificationsをONにしたい

nakanishing

総合スコア8

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2016/10/21 02:19

###前提・実現したいこと
UnityからXcodeのCapabilitiesのPush Notificationsの設定を自動的にONにしたいと考えています。

###発生している問題・エラーメッセージ
Push NotificationsをONにするだけであれば、UnityのPostProcessorでproject.pbxprojに追記することで無理矢理実現はできました(下記ソース)が、entitlementsでエラーになってしまいます。
これを解決しようと、PostProcessor内でentitlementsファイルを作成してみたものの、
こちらをPostProcessor内でプロジェクトに反映する方法が分からず途方にくれております。

こちらを解決する方法をご教授いただきたいです。

CapabilitiesのPush Notificationsの「Steps:」にある 「Add the Push Notifications entitlement to your entitlements file」 にエラーのチェックが付いてしまいます。 ![エラー](26165630d3dd53dd593bfe83bdb3fdc4.png)

###該当のソースコード

C#

1string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 2PBXProject proj = new PBXProject (); 3proj.ReadFromString (File.ReadAllText (projPath)); 4 5string[] lines = proj.WriteToString().Split ('\n'); 6List<string> newLines = new List<string> (); 7bool editFinish = false; 8 9for (int i = 0; i < lines.Length; i++) { 10 11 string line = lines [i]; 12 13 if (editFinish) { 14 newLines.Add (line); 15 } else if (line.IndexOf ("isa = PBXProject;") > -1) { 16 do { 17 newLines.Add (line); 18 line = lines [++i]; 19 } while (line.IndexOf("TargetAttributes = {") == -1); 20 21 newLines.Add("TargetAttributes = {"); 22 newLines.Add("xxxxxxxxxxxxxxx = {"); 23 newLines.Add("DevelopmentTeam = EEEEEEEEE;"); 24 newLines.Add("SystemCapabilities = {"); 25 newLines.Add("com.apple.Push = {"); 26 newLines.Add("enabled = 1;"); 27 newLines.Add("};"); 28 newLines.Add("};"); 29 newLines.Add("};"); 30 editFinish = true; 31 32 } else { 33 newLines.Add (line); 34 } 35} 36 37File.WriteAllText(projPath, string.Join ("\n", newLines.ToArray ()));

###試したこと
project.elementファイルを作成後、
PBXProjectのAddFileメソッドなどの使用を試みたものの、

###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

参考までにこちらもどうぞ。
http://qiita.com/fullcorder/items/b82c48022acd0b4ff957

投稿2017/07/03 09:44

fullcorder

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

自己解決

自己解決したのでソースを乗せておきます

PostProcessor内で以下のように書きました

c#

1private static void CreateEntitlements(string path) 2 { 3 XmlDocument document = new XmlDocument (); 4 XmlDocumentType doctype = document.CreateDocumentType ("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); 5 document.AppendChild (doctype); 6 7 XmlElement plist = document.CreateElement ("plist"); 8 plist.SetAttribute ("version", "1.0"); 9 XmlElement dict = document.CreateElement ("dict"); 10 plist.AppendChild (dict); 11 document.AppendChild (plist); 12 13 XmlElement e = (XmlElement) document.SelectSingleNode ("/plist/dict"); 14 15 XmlElement key = document.CreateElement ("key"); 16 key.InnerText = "aps-environment"; 17 e.AppendChild (key); 18 19 XmlElement value = document.CreateElement ("string"); 20 value.InnerText = "development"; 21 e.AppendChild (value); 22 23 string entitlementsPath = path + "/Unity-iPhone/{your appname}.entitlements"; 24 document.Save(entitlementsPath); 25 26 string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 27 PBXProject proj = new PBXProject (); 28 proj.ReadFromString (File.ReadAllText (projPath)); 29 string target = proj.TargetGuidByName ("Unity-iPhone"); 30 string guid = proj.AddFile (entitlementsPath, entitlementsPath); 31 proj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "Unity-iPhone/{your appname}.entitlements"); 32 proj.AddFileToBuild(target, guid); 33 proj.WriteToFile(projPath); 34 } 35 36 private static void SetCapabilities(string path) 37 { 38 string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 39 PBXProject proj = new PBXProject (); 40 proj.ReadFromString (File.ReadAllText (projPath)); 41 42 string[] lines = proj.WriteToString().Split ('\n'); 43 List<string> newLines = new List<string> (); 44 bool editFinish = false; 45 46 for (int i = 0; i < lines.Length; i++) { 47 48 string line = lines [i]; 49 50 if (editFinish) { 51 newLines.Add (line); 52 } else if (line.IndexOf ("isa = PBXProject;") > -1) { 53 do { 54 newLines.Add (line); 55 line = lines [++i]; 56 } while (line.IndexOf("TargetAttributes = {") == -1); 57 58 // 以下の内容はxcodeprojの内容にあるproject.pbxprojを参照してください 59 newLines.Add("TargetAttributes = {"); 60 newLines.Add("XXXXXXXXXXXXXXXX = {"); 61 newLines.Add("DevelopmentTeam = HOGEHOGE;"); 62 newLines.Add("SystemCapabilities = {"); 63 newLines.Add("com.apple.Push = {"); 64 newLines.Add("enabled = 1;"); 65 newLines.Add("};"); 66 newLines.Add("};"); 67 newLines.Add("};"); 68 editFinish = true; 69 70 } else { 71 newLines.Add (line); 72 } 73 } 74 75 File.WriteAllText(projPath, string.Join ("\n", newLines.ToArray ())); 76 }

投稿2016/10/21 02:52

nakanishing

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問