diff --git a/.gitignore b/.gitignore index f867683..3ceb1e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -*.meta \ No newline at end of file +*.meta +.DS_Store +.gitignore \ No newline at end of file diff --git a/Mods/StoreKit.projmods b/Mods/StoreKit.projmods index c704baf..49bfc5b 100644 --- a/Mods/StoreKit.projmods +++ b/Mods/StoreKit.projmods @@ -1,11 +1,25 @@ { "group": "Store", "libs": [], - "frameworks": ["StoreKit.framework"], + "frameworks": [], "headerpaths": [], - "files": ["iOS/Store/libStoreKit.a"], + "files": [], "folders": [], "excludes": ["^.*.meta$", "^.*.mdown$", "^.*.pdf$"], "compiler_flags": [], "linker_flags": [] + "plist": { + "CFBundleURLTypes" : [ + { + "CFBundleTypeRole": "Editor", + "CFBundleURLName" : "wechat", + "CFBundleURLSchemes":["wxyz123456789"] + }, + { + "CFBundleURLName" : "twitter", + "CFBundleURLSchemes":["www1234566"] + } + ], + "LSApplicationQueriesSchemes":["fbapi222"] + } } \ No newline at end of file diff --git a/Plist/Plist.cs b/Plist/Plist.cs index 378ecd3..d162cf5 100644 --- a/Plist/Plist.cs +++ b/Plist/Plist.cs @@ -254,6 +254,7 @@ private static object readBinary(byte[] data) private static Dictionary parseDictionary(XmlNode node) { XmlNodeList children = node.ChildNodes; + //检验了一下key/value是否成对,不成对抛出异常 if (children.Count % 2 != 0) { throw new DataMisalignedException("Dictionary elements must have an even number of child nodes"); @@ -307,6 +308,26 @@ private static void composeArray(List value, XmlWriter writer) } writer.WriteEndElement(); } + private static void composeArrayList(ArrayList value, XmlWriter writer) + { + writer.WriteStartElement("array"); + foreach (object obj in value) + { + compose(obj, writer); + } + writer.WriteEndElement(); + } + private static void composeHashtable(Hashtable value, XmlWriter writer) + { + + writer.WriteStartElement("dict"); + foreach (DictionaryEntry entry in value) + { + writer.WriteElementString("key", entry.Key.ToString()); + compose(entry.Value, writer); + } + writer.WriteEndElement(); + } private static object parse(XmlNode node) { @@ -388,10 +409,19 @@ private static void compose(object value, XmlWriter writer) { writer.WriteElementString(value.ToString().ToLower(), ""); } - else - { - throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString())); - } + else if (value is ArrayList) + { + composeArrayList((ArrayList)value, writer); + } + else if (value is Hashtable) + { + composeHashtable((Hashtable)value, writer); + } + else + { + throw new Exception(String.Format("Value type '{0}' is unhandled", value.GetType().ToString())); + } + } private static void writeDictionaryValues(Dictionary dictionary, XmlWriter writer) diff --git a/Plist/XCPlistDocument.cs b/Plist/XCPlistDocument.cs new file mode 100644 index 0000000..9ea9f66 --- /dev/null +++ b/Plist/XCPlistDocument.cs @@ -0,0 +1,109 @@ +using UnityEngine; +using System.Collections; + +using System.Collections.Generic; + +namespace PlistCS{ + + public class XCPlistDocument { + + //私有变量 + private string pathForPlist=null; + private Dictionary root=null; + + //初始化的类方法 + public static XCPlistDocument createWithPlistPath (string path){ + if (string.IsNullOrEmpty (path)) { + Debug.Log ("XCPlistDocument.createWithPlistPath parameter is unexcept!"); + return null; + } + XCPlistDocument plist = new XCPlistDocument (); + plist.pathForPlist = path; + try{ + plist.root = (Dictionary)PlistCS.Plist.readPlist(path); + }catch(System.Exception e){ + Debug.LogWarning (e.ToString()); + } + return plist; + } + //对外接口函数 + public void setBool (string key,bool value){ + + if (string.IsNullOrEmpty (key)) { + Debug.Log ("XCPlistDocument.setBool parameter is unexcept!");; + return; + } + if(root == null){ + Debug.Log ("XCPlistDocument.root is null"); + return; + } + add (key,value); + } + public void setString (string key,string value){ + if(string.IsNullOrEmpty(key)){ + Debug.Log ("XCPlistDocument.setString parameter is unexcept!"); + } + if(root == null){ + Debug.Log ("XCPlistDocument.root is null"); + return; + } + add (key,value); + } + public void setObject (string key, object value){ + if (string.IsNullOrEmpty (key)) { + Debug.Log ("XCPlistDocument.setObject parameter is unexcept"); + } + if(root == null){ + Debug.Log ("XCPlistDocument.root is null"); + return; + } + add (key, value); + } + public void setDictionary (string key,Dictionary value){ + if(string.IsNullOrEmpty(key)){ + Debug.Log ("XCPlitDocument.setDictionary is unpty"); + } + if(root == null){ + Debug.Log ("XCPlistDocument.root is null"); + return; + } + add (key,value); + } + //将更改写入磁盘 + public void synchronize(){ + if(root == null){ + Debug.Log ("XCPlistDocument.root is null"); + return; + } + if(string.IsNullOrEmpty(pathForPlist)){ + Debug.Log ("XCPlistDocument.pathForPlist is null"); + } + try{ + PlistCS.Plist.writeXml(root, pathForPlist); + } + catch(System.Exception e){ + Debug.Log (e.ToString()); + } + } + //utility + //fix key exist throw exception + private void add(string key,object value){ + if (string.IsNullOrEmpty (key)) { + Debug.Log ("XCPlistDocument.add key parameter is unexcept"); + return; + } + if(value == null){ + Debug.Log ("XCPlistDocument.add value parameter is unexcept"); + return; + } + Debug.Log ("XCPlistDocument.key:"+key); + Debug.Log ("XCPlistDocument.value:"+value.ToString()); + if (root.ContainsKey (key)) { + root [key] = value; + } else { + root.Add (key,value); + } + } + } +} + diff --git a/XCPRojectSystemCapabilities.cs b/XCPRojectSystemCapabilities.cs new file mode 100644 index 0000000..2eec7ba --- /dev/null +++ b/XCPRojectSystemCapabilities.cs @@ -0,0 +1,113 @@ +using UnityEngine; +using System.Collections; + + +namespace UnityEditor.XCodeEditor{ + + +// com.apple.ApplePay +// com.apple.ApplicationGroups.iOS +// com.apple.BackgroundModes +// com.apple.DataProtection +// com.apple.GameCenter +// com.apple.HealthKit +// com.apple.HomeKit +// com.apple.InAppPurchase +// com.apple.InterAppAudio +// com.apple.Keychain +// com.apple.Maps.iOS +// com.apple.Push +// com.apple.SafariKeychain +// com.apple.Siri +// com.apple.VPNLite +// com.apple.WAC +// com.apple.Wallet +// com.apple.iCloud + + + public enum XCProjectSystemCapabilitiesType + { + XCProjectSystemCapabilitiesTypeApplePay, + XCProjectSystemCapabilitiesTypeApplePush, + XCProjectSystemCapabilitiesTypeAppleiCloud + + }; + + public class XCProjectSystemCapabilities { + + + public static XCProjectSystemCapabilities createWithProject(PBXProject project){ + + XCProjectSystemCapabilities systemCapabilities = new XCProjectSystemCapabilities (); + systemCapabilities.weakProject = project; + return systemCapabilities; + } + public static string getEnumType(XCProjectSystemCapabilitiesType type){ + + string result=null; + switch (type) { + case XCProjectSystemCapabilitiesType.XCProjectSystemCapabilitiesTypeApplePay: + result="com.apple.ApplePay"; + break; + case XCProjectSystemCapabilitiesType.XCProjectSystemCapabilitiesTypeApplePush: + result = "com.apple.Push"; + break; + case XCProjectSystemCapabilitiesType.XCProjectSystemCapabilitiesTypeAppleiCloud: + result = "com.apple.iCloud"; + break; + } + return result; + } + + public PBXProject weakProject; + + public void visitAddSystemCapabilities (XCProjectSystemCapabilitiesType type, bool enabled){ + + if (weakProject == null) { + Debug.Log ("weakProject must not be null"); + return; + } + string destributeType = getEnumType (type); + Debug.Log ("Add System Capabilities "+destributeType); + + PBXDictionary _Attributes = (PBXDictionary)weakProject.data ["attributes"]; + PBXDictionary _TargetAttributes = (PBXDictionary)_Attributes ["TargetAttributes"]; + PBXList _targets = (PBXList)weakProject.data ["targets"]; + PBXDictionary targetDict = null; + if (_TargetAttributes.ContainsKey ((string)_targets [0])) { + targetDict = (PBXDictionary)_TargetAttributes [(string)_targets [0]]; + } else { + //不会发生 + //return; + targetDict = new PBXDictionary(); + } +// Debug.Log ("targetDict:" + targetDict); + + PBXDictionary SystemCapabilities = null; + if (targetDict != null && targetDict.ContainsKey ("SystemCapabilities")) { +// Debug.Log ("xxxxxxxxxxxxxxxxxxx"); + SystemCapabilities = (PBXDictionary)targetDict ["SystemCapabilities"]; + } else { + SystemCapabilities = new PBXDictionary(); + } + + Debug.Log ("before SystemCapabilities:" + SystemCapabilities); + if (SystemCapabilities!=null && SystemCapabilities.ContainsKey (destributeType)) { + SystemCapabilities.Remove (destributeType); + } + Debug.Log ("after SystemCapabilities:" + SystemCapabilities); + PBXDictionary enableDict = new PBXDictionary (); + enableDict.Add ("enabled", enabled?"1":"0"); + SystemCapabilities.Add (destributeType, enableDict); + + if (!targetDict.ContainsKey ("SystemCapabilities")) { + targetDict.Add("SystemCapabilities",SystemCapabilities); + } + if (!_TargetAttributes.ContainsKey ((string)_targets [0])) { + _TargetAttributes.Add((string)_targets [0],targetDict); + } + + } + } + +} diff --git a/XCPlist.cs b/XCPlist.cs index d3ff503..f17eace 100644 --- a/XCPlist.cs +++ b/XCPlist.cs @@ -53,16 +53,18 @@ public static Dictionary HashtableToDictionary (Hashtable table) public void AddPlistItems(string key, object value, Dictionary dict) { Debug.Log ("AddPlistItems: key=" + key); - - if (key.CompareTo(PlistUrlType) == 0) - { - processUrlTypes((ArrayList)value, dict); - } - else - { - dict[key] = HashtableToDictionary((Hashtable)value); + Debug.Log ("AddPlistItems: value=" + value.ToString()); + + +// if (key.CompareTo(PlistUrlType) == 0) +// { +// processUrlTypes((ArrayList)value, dict); +// } +// else +// { + dict[key] = value; plistModified = true; - } +// } } private void processUrlTypes(ArrayList urltypes, Dictionary dict) diff --git a/XCProject.cs b/XCProject.cs index 256de11..4f31fa5 100755 --- a/XCProject.cs +++ b/XCProject.cs @@ -43,7 +43,8 @@ public partial class XCProject : System.IDisposable private PBXSortedDictionary _configurationLists; private PBXProject _project; - + + #endregion @@ -333,7 +334,13 @@ public object GetObject( string guid ) { return _objects[guid]; } - + + public void AddSystemCapabilities (XCProjectSystemCapabilitiesType type, bool enabled){ + + XCProjectSystemCapabilities systemCapabilities=XCProjectSystemCapabilities.createWithProject(_project); + systemCapabilities.visitAddSystemCapabilities (type,enabled); + + } public PBXDictionary AddFile( string filePath, PBXGroup parent = null, string tree = "SOURCE_ROOT", bool createBuildFiles = true, bool weak = false ) { //Debug.Log("AddFile " + filePath + ", " + parent + ", " + tree + ", " + (createBuildFiles? "TRUE":"FALSE") + ", " + (weak? "TRUE":"FALSE") ); diff --git a/XCodePostProcess.cs b/XCodePostProcess.cs index f962014..6c6f390 100755 --- a/XCodePostProcess.cs +++ b/XCodePostProcess.cs @@ -13,7 +13,7 @@ public static class XCodePostProcess [PostProcessBuild(999)] public static void OnPostProcessBuild( BuildTarget target, string pathToBuiltProject ) { - if (target != BuildTarget.iPhone) { + if (target != BuildTarget.iOS) { Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run"); return; }