diff --git a/.travis.yml b/.travis.yml
index af000e4..91adaaa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,10 @@
language: csharp
+mono: alpha
dist: trusty
sudo: required
env:
global:
- - iOS_SDK="v1.0.0"
+ - iOS_SDK="v1.0.1"
- android_SDK=""
branches:
only:
diff --git a/Assets/Zapic/Editor/iOSBuildSettings.cs b/Assets/Zapic/Editor/iOSBuildSettings.cs
index 5a85cc6..ed46e9f 100644
--- a/Assets/Zapic/Editor/iOSBuildSettings.cs
+++ b/Assets/Zapic/Editor/iOSBuildSettings.cs
@@ -3,85 +3,197 @@
using UnityEditor.Callbacks;
using System.Collections;
using System.Text.RegularExpressions;
+using System.Reflection;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
+using UnityEditor.iOS.Xcode.Extensions;
#endif
using System.IO;
-public class iOSBuildSettings
+namespace Zapic
{
- [PostProcessBuild]
- public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
+ public class iOSBuildSettings
{
+ [PostProcessBuild]
+ public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
+ {
#if UNITY_IOS
- ConfigureXcodeSettings(buildTarget, pathToBuiltProject);
- ConfigureXcodePlist(buildTarget, pathToBuiltProject);
+ ConfigureXcodeSettings(buildTarget, pathToBuiltProject);
+ ConfigureXcodePlist(buildTarget, pathToBuiltProject);
#endif
- }
+ }
#if UNITY_IOS
- private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject)
- {
- if (buildTarget == BuildTarget.iOS)
+ private static void ConfigureXcodeSettings(BuildTarget buildTarget, string pathToBuiltProject)
{
+ if (buildTarget != BuildTarget.iOS)
+ return;
+
Debug.Log("Running Zapic Xcode Scripts");
- string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
+ string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);// pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
+ //Find and load the xcode project
var proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
- string targetGuid = proj.TargetGuidByName("Unity-iPhone");
+ //Find the unity target
+ string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
+ //Force swift to be included
Debug.Log("Zapic: Including Swift Libraries");
proj.SetBuildProperty(targetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "YES");
+ //Include the frameworks directory in search path to find Zapic.framework
Debug.Log("Zapic: Setting search path");
proj.SetBuildProperty(targetGuid, "LD_RUNPATH_SEARCH_PATHS", "$(inherited) @executable_path/Frameworks");
- //Find the existing framework id
+ //Find the id for Zapic.framework fild
var frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/Zapic.framework");
- //Try lowercase
- if(string.IsNullOrEmpty(frameworkId)){
- frameworkId = proj.FindFileGuidByProjectPath("Frameworks/Plugins/iOS/zapic.framework");
- }
-
if (string.IsNullOrEmpty(frameworkId))
{
Debug.LogError("Zapic: Unable to find iOS framework");
}
+ //Get or Add a copy files build phase
Debug.Log("Zapic:Adding embedded frameworks");
- string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Frameworks", "", "10");
+
+ string embedPhase = proj.AddCopyFilesBuildPhase(targetGuid, "Embed Zapic Framework", "", "10");
proj.AddFileToBuildSection(targetGuid, embedPhase, frameworkId);
- // Apply settings
- File.WriteAllText(projPath, proj.WriteToString());
+ const string ScriptName = "Strip Fat Library";
+
+ var scriptId = proj.ShellScriptByName(targetGuid, ScriptName);
+
+ if (string.IsNullOrEmpty(scriptId))
+ proj.AppendShellScriptBuildPhase(targetGuid, ScriptName, "/bin/sh", StripArchScript());
+
+
+ //Gets the entire project as a string
+ string contents = proj.WriteToString();
+
+ //Enable CodeSignOnCopy for the framework
+ contents = Regex.Replace(contents,
+ "(?<=Embed Frameworks)(?:.*)(\\/\\* Zapic\\.framework \\*\\/)(?=; };)",
+ m => m.Value.Replace("/* Zapic.framework */",
+ "/* Zapic.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }"));
+
+ //Save the project file
+ File.WriteAllText(projPath, contents);
Debug.Log("Zapic:Done configuring xcode settings");
}
+
+ private static void ConfigureXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
+ {
+ if (buildTarget != BuildTarget.iOS)
+ return;
+
+ Debug.Log("Zapic:Configuring plist");
+
+ // 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("NSContactsUsageDescription", "We'll use your Contacts to find people you know on Zapic.");
+ plist.root.SetString("NSPhotoLibraryUsageDescription", "Zapic will only use the Photos you select.");
+
+ // Apply editing settings to Info.plist
+ plist.WriteToFile(plistPath);
+
+ Debug.Log("Zapic:Done configuring plist");
+ }
+
+ private static string StripArchScript()
+ {
+ return @"
+echo ""Target architectures: $ARCHS""
+
+APP_PATH=""${TARGET_BUILD_DIR}/${WRAPPER_NAME}""
+
+find ""$APP_PATH"" -name '*.framework' -type d | while read -r FRAMEWORK
+do
+FRAMEWORK_EXECUTABLE_NAME=$(defaults read ""$FRAMEWORK/Info.plist"" CFBundleExecutable)
+FRAMEWORK_EXECUTABLE_PATH=""$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME""
+echo ""Executable is $FRAMEWORK_EXECUTABLE_PATH""
+echo $(lipo -info ""$FRAMEWORK_EXECUTABLE_PATH"")
+
+FRAMEWORK_TMP_PATH=""$FRAMEWORK_EXECUTABLE_PATH-tmp""
+
+# remove simulator's archs if location is not simulator's directory
+case ""${TARGET_BUILD_DIR}"" in
+*""iphonesimulator"")
+echo ""No need to remove archs""
+;;
+*)
+if $(lipo ""$FRAMEWORK_EXECUTABLE_PATH"" -verify_arch ""i386"") ; then
+lipo -output ""$FRAMEWORK_TMP_PATH"" -remove ""i386"" ""$FRAMEWORK_EXECUTABLE_PATH""
+echo ""i386 architecture removed""
+rm ""$FRAMEWORK_EXECUTABLE_PATH""
+mv ""$FRAMEWORK_TMP_PATH"" ""$FRAMEWORK_EXECUTABLE_PATH""
+fi
+if $(lipo ""$FRAMEWORK_EXECUTABLE_PATH"" -verify_arch ""x86_64"") ; then
+lipo -output ""$FRAMEWORK_TMP_PATH"" -remove ""x86_64"" ""$FRAMEWORK_EXECUTABLE_PATH""
+echo ""x86_64 architecture removed""
+rm ""$FRAMEWORK_EXECUTABLE_PATH""
+mv ""$FRAMEWORK_TMP_PATH"" ""$FRAMEWORK_EXECUTABLE_PATH""
+fi
+;;
+esac
+
+echo ""Completed for executable $FRAMEWORK_EXECUTABLE_PATH""
+echo $(lipo -info ""$FRAMEWORK_EXECUTABLE_PATH"")
+
+done
+ ";
+ }
+
+#endif
+
}
- private static void ConfigureXcodePlist(BuildTarget buildTarget, string pathToBuiltProject)
+ internal static class PBXExtensions
{
- Debug.Log("Zapic:Configuring plist");
+ ///
+ /// This is a hack to access the internal method. Replace this one unity makes it public
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AppendShellScriptBuildPhase(this PBXProject project, string targetGuid, string name, string shellPath, string shellScript)
+ {
+ Debug.Log("Zapic: Adding Shell script");
- // Samlpe of editing Info.plist
- var plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
- var plist = new PlistDocument();
- plist.ReadFromFile(plistPath);
+ MethodInfo dynMethod = project.GetType().GetMethod(
+ "AppendShellScriptBuildPhase",
+ BindingFlags.NonPublic | BindingFlags.Instance,
+ null,
+ CallingConventions.Any,
+ new System.Type[] { typeof(string), typeof(string), typeof(string), typeof(string) },
+ null);
- // Add string setting
- plist.root.SetString("NSContactsUsageDescription", "We'll use your Contacts to find people you know on Zapic.");
- plist.root.SetString("NSPhotoLibraryUsageDescription", "Zapic will only use the Photos you select.");
+ dynMethod.Invoke(project, new object[] { targetGuid, name, shellPath, shellScript });
+ }
- // Apply editing settings to Info.plist
- plist.WriteToFile(plistPath);
+ public static string ShellScriptByName(this PBXProject project, string targetGuid, string name)
+ {
+ Debug.Log("Zapic: Getting Shell script");
- Debug.Log("Zapic:Done configuring plist");
- }
+ MethodInfo dynMethod = project.GetType().GetMethod(
+ "ShellScriptByName",
+ BindingFlags.NonPublic | BindingFlags.Instance);
-#endif
+ var result = dynMethod.Invoke(project, new object[] { targetGuid, name });
+
+ return result as string;
+ }
+ }
}
+
+
diff --git a/Assets/Zapic/Examples/ExampleStartup.cs b/Assets/Zapic/Examples/ExampleStartup.cs
index 90861b8..5829015 100644
--- a/Assets/Zapic/Examples/ExampleStartup.cs
+++ b/Assets/Zapic/Examples/ExampleStartup.cs
@@ -6,7 +6,7 @@ public class ExampleStartup : MonoBehaviour
{
void Start()
{
- Zapic.Start("v0.1");
+ Zapic.Start();
}
void Update()
@@ -17,7 +17,9 @@ void Update()
{
{"SCORE",22},
{"PARAM2","abc"},
- {"PARAM3",true}
+ {"PARAM3",true},
+ {"PARAM4","\"blab"},
+ {"PAR\"AM5","\"blab"}
};
Zapic.SubmitEvent(p);
diff --git a/Assets/Zapic/IZapicInterface.cs b/Assets/Zapic/IZapicInterface.cs
new file mode 100644
index 0000000..d33e087
--- /dev/null
+++ b/Assets/Zapic/IZapicInterface.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+
+namespace ZapicSDK
+{
+ internal interface IZapicInterface
+ {
+ ///
+ /// Starts zapic. This should be called
+ /// as soon as possible during app startup.
+ ///
+ void Start();
+
+ ///
+ /// Shows the given zapic window
+ ///
+ /// View to show.
+ void Show(Views view);
+
+ ///
+ /// Gets the current players unique id.
+ ///
+ /// The unique id.
+ string PlayerId();
+
+ ///
+ /// Submit a new in-game event to zapic.
+ ///
+ /// Collection of parameter names and associate values (numeric, string, bool)
+ void SubmitEvent(Dictionary param);
+ }
+}
\ No newline at end of file
diff --git a/Assets/Zapic/MiniJSON.cs b/Assets/Zapic/MiniJSON.cs
new file mode 100644
index 0000000..3032462
--- /dev/null
+++ b/Assets/Zapic/MiniJSON.cs
@@ -0,0 +1,632 @@
+/*
+ * Copyright (c) 2013 Calvin Rien
+ *
+ * Based on the JSON parser by Patrick van Bergen
+ * http://techblog.procurios.nl/k/618/news/view/14605/14863/How-do-I-write-my-own-parser-for-JSON.html
+ *
+ * Simplified it so that it doesn't throw exceptions
+ * and can be used in Unity iPhone with maximum code stripping.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace MiniJSON
+{
+ // Example usage:
+ //
+ // using UnityEngine;
+ // using System.Collections;
+ // using System.Collections.Generic;
+ // using MiniJSON;
+ //
+ // public class MiniJSONTest : MonoBehaviour {
+ // void Start () {
+ // var jsonString = "{ \"array\": [1.44,2,3], " +
+ // "\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
+ // "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
+ // "\"unicode\": \"\\u3041 Men\u00fa sesi\u00f3n\", " +
+ // "\"int\": 65536, " +
+ // "\"float\": 3.1415926, " +
+ // "\"bool\": true, " +
+ // "\"null\": null }";
+ //
+ // var dict = Json.Deserialize(jsonString) as Dictionary;
+ //
+ // Debug.Log("deserialized: " + dict.GetType());
+ // Debug.Log("dict['array'][0]: " + ((List