Hello all,
Here i come with the best way to send the push notifications to iOS devices using Amazon Simple Notification Services in C# .Net
So here is the snippet that can push the notification very easily..
string[] strTokens = txtTokens.Text.Split(','); // Get all tokens to send the code
Parallel.ForEach(strTokens , sToken =>
{
HttpContext ctx = HttpContext.Current;
new System.Threading.Thread(() =>
{
HttpContext.Current = ctx;
SendNotificationAsync(sToken , "Your Notification Message" , 0 , "default");
}).Start();
});
public void SendNotificationAsync(string sToken , string sMessage , int iBadge , string sSound)
{
try
{
string Platform = ConfigurationManager.AppSettings["Platform"];// Application Platform
string ApplicationName = ConfigurationManager.AppSettings["ApplicationName"];//Application Name configured on SNS
string PlatformApplicationArn = ConfigurationManager.AppSettings["PlatformApplicationArn"];
AmazonSimpleNotificationServiceClient objsnsClient = new AmazonSimpleNotificationServiceClient("AWSAccessKey" , "AWSSecretKey" , "Region");
var objResponse = objsnsClient.CreatePlatformEndpointExtended(new CreatePlatformEndpointRequest
{
Token = sToken ,
PlatformApplicationArn =
PlatformApplicationArn
});
Dictionary<string , string> CustomParams = new Dictionary<string , string>();
CustomParams.Add("default" , sMessage);
CustomParams.Add("" + Platform + "" , "{\"aps\":{\"alert\": \"" + sMessage + "\",\"sound\" :\"" + sSound + "\"},\"ShortUserID\":\"123456\",\"NotificationType\":\"10\"}");
objsnsClient.Publish(new PublishRequest
{
Message = JsonConvert.SerializeObject(CustomParams) ,
MessageStructure = "json" ,
TargetArn = objResponse.EndpointArn
});
}
catch (Exception ex)
{
}
}
Here i come with the best way to send the push notifications to iOS devices using Amazon Simple Notification Services in C# .Net
So here is the snippet that can push the notification very easily..
string[] strTokens = txtTokens.Text.Split(','); // Get all tokens to send the code
Parallel.ForEach(strTokens , sToken =>
{
HttpContext ctx = HttpContext.Current;
new System.Threading.Thread(() =>
{
HttpContext.Current = ctx;
SendNotificationAsync(sToken , "Your Notification Message" , 0 , "default");
}).Start();
});
public void SendNotificationAsync(string sToken , string sMessage , int iBadge , string sSound)
{
try
{
string Platform = ConfigurationManager.AppSettings["Platform"];// Application Platform
string ApplicationName = ConfigurationManager.AppSettings["ApplicationName"];//Application Name configured on SNS
string PlatformApplicationArn = ConfigurationManager.AppSettings["PlatformApplicationArn"];
AmazonSimpleNotificationServiceClient objsnsClient = new AmazonSimpleNotificationServiceClient("AWSAccessKey" , "AWSSecretKey" , "Region");
var objResponse = objsnsClient.CreatePlatformEndpointExtended(new CreatePlatformEndpointRequest
{
Token = sToken ,
PlatformApplicationArn =
PlatformApplicationArn
});
Dictionary<string , string> CustomParams = new Dictionary<string , string>();
CustomParams.Add("default" , sMessage);
CustomParams.Add("" + Platform + "" , "{\"aps\":{\"alert\": \"" + sMessage + "\",\"sound\" :\"" + sSound + "\"},\"ShortUserID\":\"123456\",\"NotificationType\":\"10\"}");
objsnsClient.Publish(new PublishRequest
{
Message = JsonConvert.SerializeObject(CustomParams) ,
MessageStructure = "json" ,
TargetArn = objResponse.EndpointArn
});
}
catch (Exception ex)
{
}
}
Ravi Tuvar – IntelliMedia Networks
Technical Manager
Cell: (+91) 73837-94530
Email: ravituvar@yahoo.com
0 comments:
Post a Comment