diff --git a/PushSharp.Apple/AppleNotificationPayload.cs b/PushSharp.Apple/AppleNotificationPayload.cs index b3cd5c7a..1fab27ab 100644 --- a/PushSharp.Apple/AppleNotificationPayload.cs +++ b/PushSharp.Apple/AppleNotificationPayload.cs @@ -120,10 +120,23 @@ public string ToJson() foreach (string key in this.CustomItems.Keys) { + + // This section was modified to allow passing any object to the APNS. + // Previously, only primitive types were allowed. + if (this.CustomItems[key].Length == 1) - json[key] = new JValue(this.CustomItems[key][0]); + { + //json[key] = new JValue(this.CustomItems[key][0]); + json[key] = GetJsonToken(this.CustomItems[key][0]); + } else if (this.CustomItems[key].Length > 1) - json[key] = new JArray(this.CustomItems[key]); + { + //json[key] = new JArray(this.CustomItems[key]); + var list = new List(); + foreach (var customItem in this.CustomItems[key]) + list.Add(GetJsonToken(customItem)); + json[key] = new JArray(list); + } } string rawString = json.ToString(Newtonsoft.Json.Formatting.None, null); @@ -252,5 +265,15 @@ public override string ToString() { return ToJson(); } + + + private JToken GetJsonToken(object data) + { + var dataType = data.GetType(); + if ((dataType.IsValueType) || (dataType.IsAssignableFrom(typeof(string)))) + return new JValue(data); + + return JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(data)); + } } }