public AddField ( string name, AddJSONConents content ) : void | ||
name | string | |
content | AddJSONConents | |
return | void |
public static void ProcessPackagesResponse(ResponseEvent response) { if(response.data != null){ if(response.data.HasField("packages")){ JSONObject json = new JSONObject(); json.AddField("data", response.data.GetField("packages").Print(false)); GamePackagesData = JsonHelper.getObjectFromJson<List<PackageData>>(json.GetField("data").str); } if(response.data.HasField("promotions")){ JSONObject json = new JSONObject(); json.AddField("data", response.data.GetField("promotions").Print(false)); GamePromotionData = JsonHelper.getObjectFromJson<List<PromotionData>>(json.GetField("data").str); } } }
private void AddDefaultParameters() { this.data.AddField("uid", this.uid); this.data.AddField("locale", "en"); this.data.AddField("appVersion", "1.0"); this.data.AddField("apiVersion", SpilUnityImplementationBase.PluginVersion); this.data.AddField("osVersion", "1.0"); this.data.AddField("os", "android"); this.data.AddField("deviceModel", "Editor"); this.data.AddField("timezoneOffset", "0"); this.data.AddField("tto", "200"); this.data.AddField("packageName", Spil.BundleIdEditor); this.data.AddField ("sessionId", "deadbeef"); this.data.AddField("pluginName", Response.pluginName); this.data.AddField("pluginVersion", Response.pluginVersion); if(Response.provider != null && Response.externalId != null){ JSONObject externalUserIdJson = new JSONObject(); externalUserIdJson.AddField("provider", Response.provider); externalUserIdJson.AddField("userId", Response.externalId); this.data.AddField("externalUserId", externalUserIdJson); } }
/// <summary> /// This method is marked as internal and should not be exposed to developers. /// The Spil Unity SDK is not packaged as a seperate assembly yet so this method is currently visible, this will be fixed in the future. /// Internal method names start with a lower case so you can easily recognise and avoid them. /// </summary> internal override void SpilInit() { JSONObject options = new JSONObject(); options.AddField ("isUnity",true); initEventTrackerWithOptions(options.ToString()); applicationDidBecomeActive(); if (disableAutomaticRegisterForPushNotifications == false) { RegisterForPushNotifications (); CheckForRemoteNotifications(); } }
private void CheckForRemoteNotifications() { bool proccessedNotifications = false; #if UNITY_IPHONE #if UNITY_5 if (UnityEngine.iOS.NotificationServices.remoteNotificationCount > 0) { foreach(UnityEngine.iOS.RemoteNotification notification in UnityEngine.iOS.NotificationServices.remoteNotifications) { #else if (UnityEngine.NotificationServices.remoteNotificationCount > 0) { foreach(UnityEngine.RemoteNotification notification in UnityEngine.NotificationServices.remoteNotifications) { #endif foreach(var key in notification.userInfo.Keys) { if(notification.userInfo[key].GetType() == typeof(Hashtable)) { Hashtable userInfo = (Hashtable) notification.userInfo[key]; JSONObject notificationPayload = new JSONObject(); foreach(var pKey in userInfo.Keys) { if(userInfo[pKey].GetType() == typeof(string)) { string keyStr = pKey.ToString(); string value = userInfo[pKey].ToString(); notificationPayload.AddField(keyStr,value); } if(userInfo[pKey].GetType() == typeof(Hashtable)) { JSONObject innerJson = new JSONObject(); Hashtable innerTable = (Hashtable)userInfo[pKey]; foreach(var iKey in innerTable.Keys) { string iKeyStr = iKey.ToString(); if(innerTable[iKey].GetType() == typeof(Hashtable)) { Hashtable innerTableB = (Hashtable)innerTable[iKey]; JSONObject innerJsonB = new JSONObject(); foreach(var bKey in innerTableB.Keys) { innerJsonB.AddField(bKey.ToString(),innerTableB[bKey].ToString()); } innerJson.AddField(iKeyStr,innerJsonB); } if(innerTable[iKey].GetType() == typeof(string)) { string iValue = innerTable[iKey].ToString(); innerJson.AddField(iKeyStr,iValue); } } string keyStr = pKey.ToString(); notificationPayload.AddField(keyStr,innerJson); } } String notificationJsonForNative = notificationPayload.ToString().Replace("'","\""); if(!proccessedNotifications){ SendCustomEvent("notificationReceived", new Dictionary<string, string>() { { "notificationPayload", notificationJsonForNative}}); proccessedNotifications = true; } } } } #if UNITY_5 UnityEngine.iOS.NotificationServices.ClearRemoteNotifications(); #else UnityEngine.NotificationServices.ClearRemoteNotifications(); #endif } else { Debug.Log("NO REMOTE NOTIFICATIONS FOUND"); } #endif }
/// <summary> /// Merge object right into left recursively /// </summary> /// <param name="left">The left (base) object</param> /// <param name="right">The right (new) object</param> static void MergeRecur(JSONObject left, JSONObject right) { if(left.type == Type.NULL) left.Absorb(right); else if(left.type == Type.OBJECT && right.type == Type.OBJECT) { for(int i = 0; i < right.list.Count; i++) { string key = right.keys[i]; if(right[i].isContainer) { if(left.HasField(key)) MergeRecur(left[key], right[i]); else left.AddField(key, right[i]); } else { if(left.HasField(key)) left.SetField(key, right[i]); else left.AddField(key, right[i]); } } } else if(left.type == Type.ARRAY && right.type == Type.ARRAY) { if(right.Count > left.Count) { Debug.LogError("Cannot merge arrays when right object has more elements"); return; } for(int i = 0; i < right.list.Count; i++) { if(left[i].type == right[i].type) { //Only overwrite with the same type if(left[i].isContainer) MergeRecur(left[i], right[i]); else { left[i] = right[i]; } } } } }