cn.jpush.api.push.mode.PushPayload.Check C# (CSharp) Method

Check() public method

public Check ( ) : PushPayload
return PushPayload
        public PushPayload Check()
        {
            Preconditions.checkArgument(!(null == audience || null == platform), "audience and platform both should be set.");
            Preconditions.checkArgument(!(null == notification && null == message), "notification or message should be set at least one.");
            if (audience != null)
            {
                audience.Check();
            }
            if (platform != null)
            {
                platform.Check();
            }
            if (message != null)
            {
                message.Check();
            }
            if (notification != null)
            {
                notification.Check();
            }
            return this;
        }

Usage Example

        public void testNotification()
        {
            int number = ServiceHelper.generateSendno();
           
            PushPayload payload = new PushPayload();
            payload.platform = Platform.all();
            payload.audience = Audience.all(); 
            payload.options = new Options() { sendno = number };
            payload.notification = new Notification().setAlert("alert");
            payload.Check();

            JObject json = new JObject();
            json.Add("platform", JToken.FromObject("all"));
            json.Add("audience", JToken.FromObject("all"));
           

            JObject noti = new JObject();
            noti.Add("alert", JToken.FromObject("alert"));
            json.Add("notification", noti);

            JObject options = new JObject();
            options.Add("sendno", JToken.FromObject(number));
            options.Add("apns_production", JToken.FromObject(false));
            json.Add("options", options);

            var jSetting = new JsonSerializerSettings();
            jSetting.DefaultValueHandling = DefaultValueHandling.Ignore;
            var jsonString = JsonConvert.SerializeObject(payload, jSetting);
            var jsonObject = json.ToString(Formatting.None);

            Assert.AreEqual(jsonObject, jsonString);
        }
All Usage Examples Of cn.jpush.api.push.mode.PushPayload::Check