From da9fce70d021f6d1e0d0947880ee508e083e8b8e Mon Sep 17 00:00:00 2001
From: ryan gui <fucv@163.com>
Date: Sun, 31 Mar 2019 22:26:19 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E8=AE=BE=E7=BD=AESetSystemCapabilities?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Xcode/PBX/Objects.cs | 26 ++++++++++++++++++++++++++
 Xcode/PBXProject.cs  |  6 ++++++
 2 files changed, 32 insertions(+)

diff --git a/Xcode/PBX/Objects.cs b/Xcode/PBX/Objects.cs
index 01d5ebc..b582e5f 100644
--- a/Xcode/PBX/Objects.cs
+++ b/Xcode/PBX/Objects.cs
@@ -1016,6 +1016,32 @@ public override void UpdateVars()
                 }
             }
         }
+        public void SetSystemCapabilities (string target, string key, string value)
+        {
+            if (m_Properties.Contains ("attributes")) {
+                var attributes = m_Properties ["attributes"].AsDict ();
+                var targetAttributes = attributes ["TargetAttributes"].AsDict ();
+                if (targetAttributes.Contains (target)) {
+                    var targetDict = targetAttributes [target].AsDict ();
+                    if (!targetDict.Contains ("SystemCapabilities")) {
+                        var dict = targetDict.CreateDict ("SystemCapabilities");
+                        var record = dict.CreateDict (key);
+                        record.SetString ("enabled", value);
+                    } else {
+                        var dict = targetDict ["SystemCapabilities"].AsDict ();
+                        if (!dict.Contains (key)) {
+                            var record = dict.CreateDict (key);
+                            record.SetString ("enabled", value);
+                        } else {
+                            var record = dict [key].AsDict ();
+                            record.SetString ("enabled", value);
+                        }
+                    }
+                } else {
+                    //error
+                }
+            }
+        }
     }
 
 } // namespace UnityEditor.iOS.Xcode
diff --git a/Xcode/PBXProject.cs b/Xcode/PBXProject.cs
index d38cce0..5d419fd 100644
--- a/Xcode/PBXProject.cs
+++ b/Xcode/PBXProject.cs
@@ -1421,5 +1421,11 @@ internal void SetTargetAttributes(string key, string value)
             project.project.UpdateVars();
 
         }
+
+        public void SetSystemCapabilities (string target, string key, string value)
+        {
+            project.project.SetSystemCapabilities (target, key, value);
+        }
+
     }
 } // namespace UnityEditor.iOS.Xcode

From cb6ae6e75a90078ee6280e64e5a3ef16b68fb1bd Mon Sep 17 00:00:00 2001
From: ryan gui <fucv@163.com>
Date: Sun, 31 Mar 2019 22:26:26 +0800
Subject: [PATCH 2/4] Create XcodeSettingsPostProcesser.cs

---
 Xcode/XcodeSettingsPostProcesser.cs | 67 +++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 Xcode/XcodeSettingsPostProcesser.cs

diff --git a/Xcode/XcodeSettingsPostProcesser.cs b/Xcode/XcodeSettingsPostProcesser.cs
new file mode 100644
index 0000000..060607f
--- /dev/null
+++ b/Xcode/XcodeSettingsPostProcesser.cs
@@ -0,0 +1,67 @@
+﻿using System.IO;
+using UnityEngine;
+using UnityEditor;
+using UnityEditor.iOS.Xcode;
+using UnityEditor.Callbacks;
+using System.Collections;
+
+public class XcodeSettingsPostProcesser
+{
+
+    [PostProcessBuildAttribute (0)]
+    public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBuiltProject)
+    {
+
+        // Stop processing if targe is NOT iOS
+        if (buildTarget != BuildTarget.iOS)
+            return;
+
+        // Initialize PbxProject
+        var projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
+        PBXProject pbxProject = new PBXProject ();
+        pbxProject.ReadFromFile (projectPath);
+        string targetGuid = pbxProject.TargetGuidByName ("Unity-iPhone");
+
+        // Sample of adding build property
+        pbxProject.AddBuildProperty (targetGuid, "OTHER_LDFLAGS", "-all_load");
+
+        // Sample of setting build property
+        pbxProject.SetBuildProperty (targetGuid, "ENABLE_BITCODE", "NO");
+
+        // Sample of update build property
+        pbxProject.UpdateBuildProperty (targetGuid, "OTHER_LDFLAGS", new string [] { "-ObjC" }, new string [] { "-weak_framework" });
+
+        // Sample of adding REQUIRED framwrok
+        pbxProject.AddFrameworkToProject (targetGuid, "Security.framework", false);
+
+        // Sample of adding OPTIONAL framework
+        pbxProject.AddFrameworkToProject (targetGuid, "SafariServices.framework", true);
+
+        // Sample of setting compile flags
+        var guid = pbxProject.FindFileGuidByProjectPath ("Classes/UI/Keyboard.mm");
+        var flags = pbxProject.GetCompileFlagsForFile (targetGuid, guid);
+        flags.Add ("-fno-objc-arc");
+        pbxProject.SetCompileFlagsForFile (targetGuid, guid, flags);
+
+        // Apply settings
+        File.WriteAllText (projectPath, pbxProject.WriteToString ());
+
+        // Samlpe of editing Info.plist
+        var plistPath = Path.Combine (pathToBuiltProject, "Info.plist");
+        var plist = new PlistDocument ();
+        plist.ReadFromFile (plistPath);
+
+        // Add string setting
+        plist.root.SetString ("hogehogeId", "dummyid");
+
+        // Add URL Scheme
+        var array = plist.root.CreateArray ("CFBundleURLTypes");
+        var urlDict = array.AddDict ();
+        urlDict.SetString ("CFBundleURLName", "hogehogeName");
+        var urlInnerArray = urlDict.CreateArray ("CFBundleURLSchemes");
+        urlInnerArray.AddString ("hogehogeValue");
+
+        // Apply editing settings to Info.plist
+        plist.WriteToFile (plistPath);
+    }
+}
\ No newline at end of file

From 54f9a879d465f6c971ef0b5ac8b1f03361c4ac24 Mon Sep 17 00:00:00 2001
From: ryan gui <fucv@163.com>
Date: Sun, 31 Mar 2019 23:50:30 +0800
Subject: [PATCH 3/4] backup

---
 Xcode/XcodeSettingsPostProcesser.cs           |   9 +-
 ...er\345\244\215\346\235\202\347\211\210.cs" | 204 ++++++++++++++++++
 2 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 "Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"

diff --git a/Xcode/XcodeSettingsPostProcesser.cs b/Xcode/XcodeSettingsPostProcesser.cs
index 060607f..d8306bd 100644
--- a/Xcode/XcodeSettingsPostProcesser.cs
+++ b/Xcode/XcodeSettingsPostProcesser.cs
@@ -1,10 +1,14 @@
 ﻿using System.IO;
 using UnityEngine;
 using UnityEditor;
-using UnityEditor.iOS.Xcode;
+using UnityEditor.iOS.Xcode.Custom;
+//using UnityEditor.iOS.Xcode;高版本的xcode增加了一些支持，低版本有人重写了，所以就用custom
+//
 using UnityEditor.Callbacks;
 using System.Collections;
 
+//以下为示例参考
+
 public class XcodeSettingsPostProcesser
 {
 
@@ -37,6 +41,9 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBui
         // Sample of adding OPTIONAL framework
         pbxProject.AddFrameworkToProject (targetGuid, "SafariServices.framework", true);
 
+        //设置苹果商店的一些功能，Capabilities
+        pbxProject.SetSystemCapabilities(targetGuid, "com.apple.Push", "1");
+
         // Sample of setting compile flags
         var guid = pbxProject.FindFileGuidByProjectPath ("Classes/UI/Keyboard.mm");
         var flags = pbxProject.GetCompileFlagsForFile (targetGuid, guid);
diff --git "a/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs" "b/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"
new file mode 100644
index 0000000..9135e86
--- /dev/null
+++ "b/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"
@@ -0,0 +1,204 @@
+﻿using System.IO;
+using UnityEngine;
+using UnityEditor;
+using UnityEditor.iOS.Xcode.Custom;
+using UnityEditor.Callbacks;
+using System.Collections;
+using System.Collections.Generic;
+using System.Xml;
+using System;
+
+public class XcodeSettingsPostProcesser
+{
+    static string XcodePath = "";
+    [PostProcessBuildAttribute (0)]
+
+    public static void OnPostprocessBuild(BuildTarget BuildTarget, string path)
+    {
+        if (BuildTarget == BuildTarget.iOS)
+        {
+            XcodePath = path;
+            string projPath = PBXProject.GetPBXProjectPath(path);
+            PBXProject proj = new PBXProject();
+            proj.ReadFromString(File.ReadAllText(projPath));
+
+            //GenerateProjFile(proj, path);//处理Xcode工程
+
+            string plistPath = path + "/Info.plist";
+            PlistDocument plist = new PlistDocument();
+            plist.ReadFromString(File.ReadAllText(plistPath));
+
+            generatePlistFile(plist.root, path);//处理plist文件
+
+
+            //File.WriteAllText(projPath, proj.WriteToString());
+            File.WriteAllText(plistPath, plist.WriteToString());
+
+            //ParseIcon();//处理图标
+            ParseSplashXLib(new Color(34 / 255f, 44 / 255f, 55 / 255f));//修改背景色
+            //this.Buildipa();//代码请见Part2博客
+            //generateFBSettingsConfig();// FaceBook SDK
+            //generateHelpShiftConfig();//Helpshift SDK
+        }
+    }
+
+    private static void GenerateProjFile(PBXProject proj, string path)
+    {
+        string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
+
+        var codesign = Debug.isDebugBuild ? "iPhone Developer: xxxxxxxxxxx" : "iPhone Distribution: xxxxxxxx";
+        var provision = Debug.isDebugBuild ? "xxxxx1" : "xxxxx2";
+
+        proj.SetBuildProperty(target, "CODE_SIGN_IDENTITY", codesign);
+        proj.SetBuildProperty(target, "PROVISIONING_PROFILE_SPECIFIER", provision);
+        proj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "KeychainAccessGroups.plist");
+        proj.SetBuildProperty(target, "DEVELOPMENT_TEAM", "xxxxxxxxxx");
+
+        proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
+        proj.SetSystemCapabilities(target, "com.apple.Push", "1");
+        proj.SetSystemCapabilities(target, "com.apple.GameCenter", "1");
+        proj.SetSystemCapabilities(target, "com.apple.InAppPurchase", "1");
+        proj.RemoveFilesByProjectPathRecursive("Libraries/Plugins/Android"); //移除某个目录,根据开发者需求
+
+        proj.AddBuildProperty(target, "HEADER_SEARCH_PATHS", Application.dataPath + "/_PlatformAssets/Platforms/xxxxxxxx");//修改Xcode索引目录
+
+        //keychain
+        proj.AddFile(Application.dataPath + "你的目录/KeychainAccessGroups.plist", "KeychainAccessGroups.plist");
+        proj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", Application.dataPath + "你的目录/KeychainAccessGroups.plist");
+
+        //weixin framework
+        //proj.AddFrameworkToProject (target, "SystemConfiguration.framework", false);
+
+        //SvUDIDTools是UDID文件，可以忽略。
+        //AddFile添加文件到Xcode目录，返回文件GUID
+        // AddFileToBuild功能是将GUID文件添加到Xcode BuildPhases阶段
+        var fileGUID = "";
+        fileGUID = proj.AddFile(Application.dataPath + "你的目录/SvUDIDTools.h", "Libraries/Plugins/IOS/SvUDIDTool/SvUDIDTools.h");
+        proj.AddFileToBuild(target, fileGUID);
+        fileGUID = proj.AddFile(Application.dataPath + "你的目录/SvUDIDTools.m", "Libraries/Plugins/IOS/SvUDIDTool/SvUDIDTools.m");
+        proj.AddFileToBuild(target, fileGUID);//添加到Xcode BuildPhases阶段
+
+        //todo 多语言支持后续完善
+        //localizable  自动添加Xcode语言文件
+        //var infoDirs = Directory.GetDirectories(Application.dataPath + "你的目录/lang/infoplist/");
+        //for (var i = 0; i < infoDirs.Length; ++i)
+        //{
+        //    var files = Directory.GetFiles(infoDirs[i], "*.strings");
+
+        //proj.AddLocalization(files[0], "InfoPlist.strings", "InfoPlist.strings");
+        //}
+
+        //var localdirs = Directory.GetDirectories(Application.dataPath + "你的目录/lang/localizable/");
+        //for (var i = 0; i < localdirs.Length; ++i)
+        //{
+        //    var files = Directory.GetFiles(localdirs[i], "*.strings");
+        //    proj.AddLocalization(files[0], "Localizable.strings", "Localizable.strings");
+        //}
+        fileGUID = proj.AddFile(Application.dataPath + "/Plugins/IOS/notificationsound.caf", "notificationsound.caf"); //添加推送音效
+        proj.AddFileToBuild(target, fileGUID);
+    }
+
+    private static void generatePlistFile(PlistElementDict rootDict, string path)
+    {
+        rootDict.SetString("CFBundleIdentifier", "com.gekko.rok");
+        rootDict.SetString("CFBundleDisplayName", "Rage of Kings");
+        //rootDict.SetString("CFBundleVersion", GetVer());
+        rootDict.SetString("NSPhotoLibraryUsageDescription", "Use Photo");
+        rootDict.SetString("NSCameraUsageDescription", "Use Camera");
+        //rootDict.SetString("CFBundleShortVersionString", GKVersion.GAME_VERSION);
+        rootDict.SetString("ITSAppUsesNonExemptEncryption", "false");
+        rootDict.SetString("LSHasLocalizedDisplayName", "true");
+
+        //weixin scheme
+        PlistElementArray urlArray = null;
+        if (!rootDict.values.ContainsKey("CFBundleURLTypes"))
+        {
+            urlArray = rootDict.CreateArray("CFBundleURLTypes");
+        }
+        else
+        {
+            urlArray = rootDict.values["CFBundleURLTypes"].AsArray();
+        }
+        var urlTypeDict = urlArray.AddDict();
+        urlTypeDict.SetString("CFBundleURLName", "weixin");
+        var urlScheme = urlTypeDict.CreateArray("CFBundleURLSchemes");
+        urlScheme.AddString("weixin_id");
+
+        if (!rootDict.values.ContainsKey("LSApplicationQueriesSchemes"))
+        {
+            urlArray = rootDict.CreateArray("LSApplicationQueriesSchemes");
+        }
+        else
+        {
+            urlArray = rootDict["LSApplicationQueriesSchemes"].AsArray();
+        }
+        urlArray.AddString("weixin");
+
+        //Gamecenter
+        if (rootDict.values.ContainsKey("UIRequiredDeviceCapabilities"))
+        {
+            rootDict.values.Remove("UIRequiredDeviceCapabilities");
+        }
+        var arr = rootDict.CreateArray("UIRequiredDeviceCapabilities");
+        arr.AddString("armv7");
+        arr.AddString("gamekit");
+    }
+
+    protected static void ParseIcon()
+    {
+        string sourcePath = "/_ExportTextures/appIcon/{0}.png";
+        var icoList = new List<string>() {
+        "Icon",
+        "Icon-72",
+        "Icon-76",
+        "Icon-120",
+        "Icon@2x",
+        "Icon-144",
+        "Icon-152",
+        "Icon-167",
+        "Icon-180",
+        "Icon-Store"//1024*1024 , xcode9+
+        };
+        foreach (var ico in icoList)
+        {
+            File.Copy(Application.dataPath + string.Format(sourcePath, ico), XcodePath + string.Format("/Unity-iPhone/Images.xcassets/AppIcon.appiconset/{0}.png", ico), true);
+        }
+    }
+
+    //using System.Xml;
+    protected static void ParseSplashXLib(Color color)
+    {
+        Action<string> ModifyXML = (xmlPath) => {
+            XmlDocument xmlDoc = new XmlDocument();
+            xmlDoc.Load(xmlPath);
+            XmlNodeList nodelist = xmlDoc.SelectSingleNode("document").ChildNodes;
+            foreach (XmlElement item in nodelist)
+            {
+                if (item.Name == "objects")
+                {
+                    foreach (XmlElement item1 in item.ChildNodes)
+                    {
+                        if (item1.Name == "view")
+                        {
+                            foreach (XmlElement item2 in item1.ChildNodes)
+                            {
+                                if (item2.Name == "color")
+                                {
+                                    item2.SetAttribute("red", color.r.ToString());
+                                    item2.SetAttribute("green", color.g.ToString());
+                                    item2.SetAttribute("blue", color.b.ToString());
+                                    item2.SetAttribute("alpha", color.a.ToString());
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            xmlDoc.Save(xmlPath);
+        };
+
+        ModifyXML(XcodePath + "/LaunchScreen-iPhone.xib");
+        ModifyXML(XcodePath + "/LaunchScreen-iPad.xib");
+    }
+
+}
\ No newline at end of file

From 82317bbd914f8864f5a26284a61588d72ce59e59 Mon Sep 17 00:00:00 2001
From: ryan gui <fucv@163.com>
Date: Wed, 3 Apr 2019 00:45:22 +0800
Subject: [PATCH 4/4] update

---
 .gitignore                                    |  2 ++
 Xcode/XcodeSettingsPostProcesser.cs           |  1 +
 ...er\345\244\215\346\235\202\347\211\210.cs" | 31 +++++++++++++++++++
 3 files changed, 34 insertions(+)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f77e4ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+
+*.DS_Store
diff --git a/Xcode/XcodeSettingsPostProcesser.cs b/Xcode/XcodeSettingsPostProcesser.cs
index d8306bd..bc50777 100644
--- a/Xcode/XcodeSettingsPostProcesser.cs
+++ b/Xcode/XcodeSettingsPostProcesser.cs
@@ -37,6 +37,7 @@ public static void OnPostprocessBuild (BuildTarget buildTarget, string pathToBui
 
         // Sample of adding REQUIRED framwrok
         pbxProject.AddFrameworkToProject (targetGuid, "Security.framework", false);
+        pbxProject.AddFrameworkToProject(targetGuid, "AdSupport.framework", false);
 
         // Sample of adding OPTIONAL framework
         pbxProject.AddFrameworkToProject (targetGuid, "SafariServices.framework", true);
diff --git "a/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs" "b/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"
index 9135e86..1ec9929 100644
--- "a/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"
+++ "b/Xcode/XcodeSettingsPostProcesser\345\244\215\346\235\202\347\211\210.cs"
@@ -58,6 +58,37 @@ private static void GenerateProjFile(PBXProject proj, string path)
         proj.SetSystemCapabilities(target, "com.apple.Push", "1");
         proj.SetSystemCapabilities(target, "com.apple.GameCenter", "1");
         proj.SetSystemCapabilities(target, "com.apple.InAppPurchase", "1");
+
+        //以下为旧版本可以设置的内置功能字符串，有很多功能不知只是设置开启，有其他参数需要配置，将来使用时最好升级xcode版本
+        /*
+        "com.apple.AccessWiFi",
+        "com.apple.ApplePay",
+        "com.apple.ApplicationGroups.iOS",
+        "com.apple.AutoFillCredentialProvider",
+        "com.apple.BackgroundModes",
+        "com.apple.ClassKit",
+        "com.apple.DataProtection",
+        "com.apple.GameCenter.iOS",
+        "com.apple.GameControllers.appletvos",
+        "com.apple.HealthKit",
+        "com.apple.HomeKit",
+        "com.apple.HotspotConfiguration",
+        "com.apple.InAppPurchase",
+        "com.apple.InterAppAudio",
+        "com.apple.Keychain",
+        "com.apple.Maps.iOS",
+        "com.apple.Multipath",
+        "com.apple.NearFieldCommunicationTagReading",
+        "com.apple.NetworkExtensions.iOS",
+        "com.apple.Push",
+        "com.apple.SafariKeychain",
+        "com.apple.Siri",
+        "com.apple.VPNLite",
+        "com.apple.WAC",
+        "com.apple.Wallet",
+        "com.apple.iCloud"
+        */
+
         proj.RemoveFilesByProjectPathRecursive("Libraries/Plugins/Android"); //移除某个目录,根据开发者需求
 
         proj.AddBuildProperty(target, "HEADER_SEARCH_PATHS", Application.dataPath + "/_PlatformAssets/Platforms/xxxxxxxx");//修改Xcode索引目录
