PushwooshBuildManager.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 
  2. //Thank you Unity for the best defines ever
  3. #define UNITY_3_PLUS
  4. #define UNITY_4_PLUS
  5. #define UNITY_5_PLUS
  6. #if UNITY_2_6
  7. #define UNITY_2_X
  8. #undef UNITY_3_PLUS
  9. #undef UNITY_4_PLUS
  10. #undef UNITY_5_PLUS
  11. #elif UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
  12. #define UNITY_3_X
  13. #undef UNITY_4_PLUS
  14. #undef UNITY_5_PLUS
  15. #elif UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9
  16. #define UNITY_4_X
  17. #undef UNITY_5_PLUS
  18. #elif UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_5_7 || UNITY_5_8 || UNITY_5_9
  19. #define UNITY_5_X
  20. #endif
  21. using UnityEngine;
  22. using UnityEditor;
  23. using UnityEditor.Callbacks;
  24. using System.Collections;
  25. using System.IO;
  26. using System.Diagnostics;
  27. using System.Text.RegularExpressions;
  28. using System.Xml;
  29. #if UNITY_EDITOR_OSX && UNITY_5_X
  30. using UnityEditor.iOS.Xcode;
  31. #endif
  32. public class PushwooshBuildManager : MonoBehaviour
  33. {
  34. [PostProcessBuild]
  35. private static void onPostProcessBuildPlayer(BuildTarget target, string pathToBuiltProject) {
  36. #if UNITY_EDITOR_OSX && UNITY_5_X
  37. if (target == BuildTarget.iOS) {
  38. UnityEngine.Debug.Log ("Path to built project: " + pathToBuiltProject);
  39. string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
  40. UnityEngine.Debug.Log ("Project Path: " + projPath);
  41. PBXProject proj = new PBXProject();
  42. proj.ReadFromString(File.ReadAllText(projPath));
  43. string projTarget = proj.TargetGuidByName("Unity-iPhone");
  44. UnityEngine.Debug.Log ("Project Target: " + projTarget);
  45. proj.AddFrameworkToProject(projTarget, "Security.framework", false);
  46. proj.AddBuildProperty(projTarget, "OTHER_LDFLAGS", "-ObjC -lz -lstdc++");
  47. File.WriteAllText(projPath, proj.WriteToString());
  48. }
  49. #endif
  50. if (target == BuildTarget.WP8Player) {
  51. postProcessWP8Build(pathToBuiltProject);
  52. }
  53. }
  54. private static void postProcessWP8Build(string pathToBuiltProject) {
  55. string manifestFilePath = Path.Combine( Path.Combine (pathToBuiltProject, PlayerSettings.productName), "Properties/WMAppManifest.xml");
  56. if (!File.Exists (manifestFilePath)) {
  57. UnityEngine.Debug.LogError ("Windows Phone manifest not found: " + manifestFilePath);
  58. return;
  59. }
  60. XmlDocument manifest = new XmlDocument ();
  61. manifest.Load(manifestFilePath);
  62. XmlNode capabilities = manifest.SelectSingleNode ("//Capabilities");
  63. XmlNodeList matchingCapability = manifest.SelectNodes("//Capability[@Name='ID_CAP_IDENTITY_DEVICE']");
  64. if (matchingCapability.Count == 0) {
  65. XmlElement newCapability = manifest.CreateElement("Capability");
  66. newCapability.SetAttribute("Name", "ID_CAP_IDENTITY_DEVICE");
  67. capabilities.AppendChild(newCapability);
  68. }
  69. matchingCapability = manifest.SelectNodes("//Capability[@Name='ID_CAP_PUSH_NOTIFICATION']");
  70. if (matchingCapability.Count == 0) {
  71. XmlElement newCapability = manifest.CreateElement("Capability");
  72. newCapability.SetAttribute("Name", "ID_CAP_PUSH_NOTIFICATION");
  73. capabilities.AppendChild(newCapability);
  74. }
  75. manifest.Save (manifestFilePath);
  76. UnityEngine.Debug.Log ("Windows Phone manifest sucessfully patched");
  77. }
  78. }