コード例 #1
0
 /// <summary>
 /// Build with GCM specific message that will be delivered through GCM.
 /// Override the GCM delivery flag if already set by <see cref="GCMMessage"/>
 /// </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 WithGCMMessage(GCMMessage message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("GCMMessage can not be null");
     }
     this.mGcm = message.ToJson();
     return(this);
 }
コード例 #2
0
        public void Test_0005_GCMMessage()
        {
            GCMData data = new GCMData();

            data.Put("payload", "abc");
            GCMMessage apns = GCMMessage.CreateBuilder()
                              .WithGCMData(data)
                              .WithCollapseKey("CollapseKey")
                              .WithDelayWhileIdle(true)
                              .WithRestrictedPackageName("RestrictedPackageName")
                              .WithTimeToLive(4)
                              .Build();
            JsonObject json = apns.ToJson();

            Assert.AreEqual(true, json.Get("enabled"));
            Assert.AreEqual("CollapseKey", json.Get("collapseKey"));
            Assert.AreEqual(true, json.Get("delayWhileIdle"));
            Assert.AreEqual(4, json.Get("timeToLive"));
            Assert.AreEqual("RestrictedPackageName", json.Get("restrictedPackageName"));
            Assert.AreEqual("abc", json.GetJsonObject("data").Get("payload"));
        }