Last active
February 15, 2017 02:20
-
-
Save st0326s/bbed94455c5c494ca22ce9feeb7522cc to your computer and use it in GitHub Desktop.
OnPostProcessBuild関係 メモ書き ref: http://qiita.com/satotin/items/a56de689bca82e24df29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if NOTIFICATION_SYSTEM_ENABLE | |
// Change value of CFBundleVersion in Xcode plist | |
var buildKey = "UIBackgroundModes"; | |
plist.root.CreateArray (buildKey).AddString ("remote-notification"); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// プッシュ通知追加位置に使用する状態 | |
/// </summary> | |
private enum FindEnum | |
{ | |
INITIAL = 0, | |
FIND_CAPABILITIES, | |
PROVISIONING_STYLE, | |
NON_CAPABILITIES, | |
ADD_END | |
} | |
/// <summary> | |
/// entitlementsファイル拡張子 | |
/// </summary> | |
private const string ENTITLEMENTS_SUFFIX = ".entitlements"; | |
/// <summary> | |
/// PBXプロジェクトファイルパス | |
/// </summary> | |
private const string PBX_PROJECT_FILE_PATH = "/Unity-iPhone.xcodeproj/project.pbxproj"; | |
/// <summary> | |
/// アプリ名. | |
/// </summary> | |
private const string APP_NAME = "アプリ名"; | |
/// <summary> | |
/// Capabilitiesの発見開始の文字列 | |
/// </summary> | |
private const string CAPABILITIES_FIND_STRING = "/* Begin PBXProject section */"; | |
/// <summary> | |
/// Capabilities文字列の1つ上の行を検索するための文字列 | |
/// </summary> | |
private const string PROVISIONINGSTYLE_STRING = "ProvisioningStyle"; | |
/// <summary> | |
/// SystemCapabilitiesキー検索用の文字列 | |
/// </summary> | |
private const string SYSTEMCAPABILITIES_STRING = "SystemCapabilities"; | |
/// XCodeプロジェクト名. | |
/// Unityでビルドした際のデフォルトターゲット名は"Unity-iPhone". | |
private const string XCODE_PROJECT_NAME = "Unity-iPhone"; | |
/// iOSのプラグインディレクトリパス. | |
private const string IOS_PLUGINS_DIR_PATH = "Assets/Plugins/iOS"; | |
/// XCodeのInfo.plistファイル名. | |
private const string XCODE_INFO_PLIST_FILE_NAME = "Info.plist"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// プッシュ通知設定をXcodeの設定に追加する。 | |
/// </summary> | |
/// <param name="path">Path.=ファイルをreadするパス</param> | |
private static void AddPushNotificationCapabilities(string path) | |
{ | |
string projPath = path + PBX_PROJECT_FILE_PATH; | |
PBXProject proj = new PBXProject (); | |
proj.ReadFromString (File.ReadAllText (projPath)); | |
List<string> pbxLineList = new List<string> (); | |
List<string> pbxSaveLineList = new List<string> (); | |
string[] lines = proj.WriteToString().Split ('\n'); | |
pbxLineList.AddRange (lines); | |
int loopMax = pbxLineList.Count; | |
FindEnum FindState = FindEnum.INITIAL; | |
for(int i = 0; i < loopMax; i++) | |
{ | |
// XcodeProject保存用リストに追加 | |
pbxSaveLineList.Add (pbxLineList [i]); | |
if (pbxLineList [i].IndexOf (CAPABILITIES_FIND_STRING) >= 0) | |
{ | |
FindState = FindEnum.FIND_CAPABILITIES; | |
} | |
if ((FindState == FindEnum.FIND_CAPABILITIES) && | |
(pbxLineList [i].IndexOf (PROVISIONINGSTYLE_STRING) >= 0)) | |
{ | |
FindState = FindEnum.PROVISIONING_STYLE; | |
} | |
if (FindState == FindEnum.PROVISIONING_STYLE) | |
{ | |
// capabilities文字列が存在しない | |
if (pbxLineList [i + 1].IndexOf (SYSTEMCAPABILITIES_STRING) < 0) { | |
// capabilities | |
pbxSaveLineList.Add ("SystemCapabilities = {"); | |
FindState = FindEnum.NON_CAPABILITIES; | |
} | |
else | |
{ | |
i++; | |
pbxSaveLineList.Add (pbxLineList [i]); | |
} | |
// push add | |
pbxSaveLineList.Add("com.apple.Push = {"); | |
pbxSaveLineList.Add("enabled = 1;"); | |
pbxSaveLineList.Add("};"); | |
// capabilities文字列が存在しない | |
if (FindState == FindEnum.NON_CAPABILITIES) | |
{ | |
// capabilitiesの閉じカッコ | |
pbxSaveLineList.Add("}"); | |
} | |
FindState = FindEnum.ADD_END; | |
} | |
} | |
File.WriteAllText(projPath, string.Join ("\n", pbxSaveLineList.ToArray ())); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; | |
PBXProject proj = new PBXProject (); | |
proj.ReadFromString (File.ReadAllText (projPath)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Begin PBXProject section */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ProvisioningStyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SystemCapabilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SystemCapabilities = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
com.apple.Push = { | |
enabled = 1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment