Quantcast
Channel: jpush Wiki Rss Feed
Viewing all articles
Browse latest Browse all 21

Updated Wiki: class: JPushClient

$
0
0

Class JPushClient
This class is the core for calling JPush API via official RESTful interfaces. There are two major features:

  • Send Push message for iOS and/or Android
  • Track delivery status via multiple message ID, which returned by JPush Service.

 

Sample:

Here is a sample based on .NET console application.

class Program
 {
      staticvoid Main(string[] args)
      {
          var appKey = "1234567890abcdef"; // Your App Key from JPushvar masterSecret = "1234567890abcdef"; // Your Master Secret from JPush
          Dictionary<string, string> customizedValues = new Dictionary<string, string>();
          customizedValues.Add("CK1", "CV1");
          customizedValues.Add("CK2", "CV2");
          JPushClient client = new JPushClient(appKey, masterSecret, false);
          var response = client.SendPushMessage(new PushMessageRequest
          {
              MessageType = MessageType.Notification,
              Platform = PushPlatform.Android,
              Description = "DotNET",
              PushType = PushType.Broadcast,
              IsTestEnvironment = true,
              Message = new PushMessage
              {
                  Content = "Hello, this is a test push from .NET. Have a nice day!",
                  PushTitle = "A title.",
                  Sound = "YourSound",
                  CustomizedValue = customizedValues
              }
          });
          Console.WriteLine(response.ResponseCode.ToString() + ":"+ response.ResponseMessage);
          Console.WriteLine("Push sent.");
          Console.WriteLine(response.ResponseCode.ToString() + ":"+ response.ResponseMessage);
          List<string> idToCheck = new List<string>();
          idToCheck.Add(response.MessageId);
          var statusList = client.QueryPushMessageStatus(idToCheck);
          Console.WriteLine("Status track is completed.");
          if (statusList != null)
          {
          foreach (var one in statusList)
              {
                  Console.WriteLine(string.Format("Id: {0}, Android: {1}, iOS: {2}", one.MessageId, one.AndroidDeliveredCount, one.ApplePushNotificationDeliveredCount));
              }
          }
          Console.WriteLine("Press any key to exit.");
          Console.Read();
      }
  }

RESTful API reference: http://docs.jpush.cn/display/dev/Index

NOTE:

  • As official document defined, the message ID collection is limited by 1000 in one track request. So if more than 1000 is set in collection for tracking, only the first 1000 can get status information in result.
  • Regarding to the possible change of official RESTful API, current client is cliamed to base on v2 version of JPush.

Viewing all articles
Browse latest Browse all 21

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>