Hello I am usign this code.which i mention below.but i am getting error:
Specified argument was out of the range of valid values.
Parameter name: Your Certificate is not a valid certificate for connecting to Apple's APNS servers
My Code:
JavaScript
// Configuration (NOTE: .pfx can also be used here)
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox,
Server.MapPath("Bobl.p12"), "dipak12");
// Create a new broker
var apnsBroker = new ApnsServiceBroker(config);
// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
{
aggregateEx.Handle(ex =>
{
// See what kind of exception it was to further diagnose
if (ex is ApnsNotificationException)
{
var notificationException = (ApnsNotificationException)ex;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine("Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
}
else
{
// Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine("Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
};
apnsBroker.OnNotificationSucceeded += (notification) =>
{
Console.WriteLine("Apple Notification Sent!");
};
// Start the broker
apnsBroker.Start();
//foreach (var deviceToken in MY_DEVICE_TOKENS) {
// Queue a notification to send apnsBroker.QueueNotification(new ApnsNotification
C#
{
DeviceToken = "f30cb6b2c1d93da1049903ab32043423de5832898d8a92c26eec7b68892a3258",
Payload = JObject.Parse("{\"aps\":{\"badge\":7}}")
});
//}
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop();3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Kanak46 pointsPosted Apr 24, 2017, 4:37 AM EDT
DataLayer dl = new DataLayer(); DataTable dt = new DataTable(); dt = dl.ExeQueryStrRetDTDL("select 'your app id here' AS TokenID", "1"); string path = HttpContext.Current.Server.MapPath("/Resources/dev.p12"); var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, path, "123", true); // Create a new broker var apnsBroker = new ApnsServiceBroker(config); string messagejson = "{\"aps\":{\"title\":\"" + txttitle.Text.Trim() + "\",\"body\":\"" + txtmessage.Text.Trim() + "\",\"alert\":\"welcome cpl\",\"badge\":1,\"sound\":\"default\",\"GoSocialHub\":\"1\"}}"; // string messagejson = "{\"alert\":{\"title\":\"" + txttitle.Text.Trim() + "\",\"body\":\"" + txtmessage.Text.Trim() + "\",\"action-loc-key\" : \"PLAY\"},\"badge\":1,\"sound\":\"chime.aiff\"}"; // Wire up events apnsBroker.OnNotificationFailed += (notification, aggregateEx) => { aggregateEx.Handle(ex => { if (ex is ApnsNotificationException) { var notificationException = (ApnsNotificationException)ex; var apnsNotification = notificationException.Notification; var statusCode = notificationException.ErrorStatusCode; Console.WriteLine("Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}"); } else { Console.WriteLine("Apple Notification Failed for some unknown reason : {ex.InnerException}"); } return true; }); }; apnsBroker.OnNotificationSucceeded += (notification) => { Console.WriteLine("Apple Notification Sent!"); }; // Start the broker apnsBroker.Start(); //foreach (var deviceToken in MY_DEVICE_TOKENS) { // Queue a notification to send for (int i = 0; i < dt.Rows.Count; i++) {{ DeviceToken = dt.Rows[i]["Tokenid"].ToString(), Payload = JObject.Parse("{\"aps\":" + messagejson + ",\"acme1\" : \"bar\",\"acme2\" : [ \"bang\", \"whiz\" ]}") }); } apnsBroker.Stop();Ajad Patel76 pointsPosted Apr 24, 2017, 6:19 AM EDT
Kanak46 pointsPosted Apr 24, 2017, 6:46 AM EDT