/// <summary>
 /// Build with APNS specific message that will be delivered through APNS.
 /// Override the APNS delivery flag if already set by <see cref="EnableAPNS(bool)"/>
 ///
 /// </summary>
 /// <remarks></remarks>
 /// <param name="message">Message.</param>
 /// <returns>Builder of the message.</returns>
 /// <exception cref='ArgumentNullException'>
 /// Is thrown when an argument is null.
 /// </exception>
 public Builder WithAPNSMessage(APNSMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("APNSMessage can not be null");
     }
     this.mApns = message.ToJson();
     return(this);
 }
Esempio n. 2
0
        public void Test_0003_APNSMessage()
        {
            APNSData data = new APNSData();

            data.Put("payload", "abc");
            APNSMessage apns = APNSMessage.CreateBuilder()
                               .WithAPNSData(data)
                               .WithAlertActionLocKey("ActionLocKey")
                               .WithAlertBody("Body")
                               .WithAlertLaunchImage("LaunchImage")
                               .WithAlertLocArgs(new string[] { "Args1", "Args2" })
                               .WithAlertLocKey("LocKey")
                               .WithAlertTitle("title")
                               .WithAlertSubtitle("subtitle")
                               .WithBadge(3)
                               .WithContentAvailable(1)
                               .WithSound("Sound")
                               .WithMutableContent(1)
                               .Build();
            JsonObject json = apns.ToJson();

            Assert.AreEqual(true, json.Get("enabled"));
            Assert.AreEqual(3, json.Get("badge"));
            Assert.AreEqual(1, json.Get("contentAvailable"));
            Assert.AreEqual(1, json.Get("mutableContent"));
            Assert.AreEqual("Sound", json.Get("sound"));
            Assert.AreEqual("abc", json.GetJsonObject("data").Get("payload"));
            Assert.AreEqual("ActionLocKey", json.GetJsonObject("alert").Get("actionLocKey"));
            Assert.AreEqual("title", json.GetJsonObject("alert").Get("title"));
            Assert.AreEqual("subtitle", json.GetJsonObject("alert").Get("subtitle"));
            Assert.AreEqual("Body", json.GetJsonObject("alert").Get("body"));
            Assert.AreEqual("LaunchImage", json.GetJsonObject("alert").Get("launchImage"));
            Assert.AreEqual("Args1", json.GetJsonObject("alert").GetJsonArray("locArgs").Get(0));
            Assert.AreEqual("Args2", json.GetJsonObject("alert").GetJsonArray("locArgs").Get(1));
            Assert.AreEqual("LocKey", json.GetJsonObject("alert").Get("locKey"));
        }