public static void OnPostProcessBuild(BuildTarget target, string path) { // If integrating with facebook on any platform, throw a warning if the app id is invalid if (!FBSettings.IsValidAppId) { Debug.LogWarning("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); } if (target == BuildTarget.iOS) { UnityEditor.XCodeEditor.XCProject project = new UnityEditor.XCodeEditor.XCProject(path); // Find and run through all projmods files to patch the project string projModPath = System.IO.Path.Combine(Application.dataPath, "Facebook/Editor/iOS"); var files = System.IO.Directory.GetFiles(projModPath, "*.projmods", System.IO.SearchOption.AllDirectories); foreach (var file in files) { project.ApplyMod(Application.dataPath, file); } project.Save(); PlistMod.UpdatePlist(path, FBSettings.AppId); FixupFiles.FixSimulator(path); FixupFiles.AddVersionDefine(path); FixupFiles.FixColdStart(path); } if (target == BuildTarget.Android) { // The default Bundle Identifier for Unity does magical things that causes bad stuff to happen if (PlayerSettings.bundleIdentifier == "com.Company.ProductName") { Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly."); } if (!FacebookAndroidUtil.IsSetupProperly()) { Debug.LogError("Your Android setup is not correct. See Settings in Facebook menu."); } if (!ManifestMod.CheckManifest()) { // If something is wrong with the Android Manifest, try to regenerate it to fix it for the next build. ManifestMod.GenerateManifest(); } } }
public static void OnPostProcessBuild(BuildTarget target, string path) { // If integrating with facebook on any platform, throw a warning if the app id is invalid if (!FBSettings.IsValidAppId) { Debug.LogWarning("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); } bool needsNewClassnames = IsVersion42OrLater(); if (target == BuildTarget.iPhone) { UnityEditor.XCodeEditor.XCProject project = new UnityEditor.XCodeEditor.XCProject(path); // Find and run through all projmods files to patch the project string projModPath = System.IO.Path.Combine(Application.dataPath, "Facebook/Editor/iOS"); var files = System.IO.Directory.GetFiles(projModPath, "*.projmods", System.IO.SearchOption.AllDirectories); foreach (var file in files) { project.ApplyMod(Application.dataPath, file); } project.Save(); PlistMod.UpdatePlist(path, FBSettings.AppId); FixupFiles.FixSimulator(path); if (needsNewClassnames) { FixupFiles.AddVersionDefine(path); } } if (target == BuildTarget.Android) { // The default Bundle Identifier for Unity does magical things that causes bad stuff to happen if (PlayerSettings.bundleIdentifier == "com.Company.ProductName") { Debug.LogError("The default Unity Bundle Identifier (com.Company.ProductName) will not work correctly."); } } }
public static void UpdatePlist(string path, string appId, string[] allPossibleAppIds) { string text = Path.Combine(path, "Info.plist"); if (string.IsNullOrEmpty(appId) || appId.Equals("0")) { Debug.LogError("You didn't specify a Facebook app ID. Please add one using the Facebook menu in the main Unity editor."); return; } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(text); XmlNode xmlNode = PlistMod.FindPlistDictNode(xmlDocument); if (xmlNode == null) { Debug.LogError("Error parsing " + text); return; } if (!PlistMod.HasKey(xmlNode, "FacebookAppID")) { PlistMod.AddChildElement(xmlDocument, xmlNode, "key", "FacebookAppID"); PlistMod.AddChildElement(xmlDocument, xmlNode, "string", appId); } if (!PlistMod.HasKey(xmlNode, "CFBundleURLTypes")) { PlistMod.AddChildElement(xmlDocument, xmlNode, "key", "CFBundleURLTypes"); XmlElement parent = PlistMod.AddChildElement(xmlDocument, xmlNode, "array", null); XmlElement parent2 = PlistMod.AddChildElement(xmlDocument, parent, "dict", null); PlistMod.AddChildElement(xmlDocument, parent2, "key", "CFBundleURLSchemes"); XmlElement parent3 = PlistMod.AddChildElement(xmlDocument, parent2, "array", null); for (int i = 0; i < allPossibleAppIds.Length; i++) { string str = allPossibleAppIds[i]; PlistMod.AddChildElement(xmlDocument, parent3, "string", "fb" + str); } } xmlDocument.Save(text); StreamReader streamReader = new StreamReader(text); string text2 = streamReader.ReadToEnd(); streamReader.Close(); int num = text2.IndexOf("<!DOCTYPE plist PUBLIC", StringComparison.Ordinal); if (num <= 0) { return; } int num2 = text2.IndexOf('>', num); if (num2 <= 0) { return; } string text3 = text2.Substring(0, num); text3 += "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"; text3 += text2.Substring(num2 + 1); StreamWriter streamWriter = new StreamWriter(text, false); streamWriter.Write(text3); streamWriter.Close(); }