Friday, February 10, 2017

To send push notification's to IOS device

To send push notifications to the IOS devices from WCF service we need to first install the push sharp  and the Newtonsoft.Json library from the NuGet package manager

To install the push sharp from package manager console type the following command 
Install-Package PushSharp
https://www.nuget.org/packages/PushSharp/
To install the Newtonsoft.Json from package manager console type the following command
 Install-Package Newtonsoft.Json
https://www.nuget.org/packages/Newtonsoft.Json/9.0.2-beta2 

After installing the package write the following code to send the notifications.



using Newtonsoft.Json.Linq;
using PushSharp.Apple;

  public void IosPushNotifications()
        {
            var certificate = File.ReadAllBytes("Add your certificate location");
            var configuration = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, certificate, "your certificate password");

            var ServiceBroker = new ApnsServiceBroker(configuration);

            string message = "Your message";
            ServiceBroker.Start();
            ServiceBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = "18545dd4eredf47834e4er4exxxxxxxxxxxxxxxxxxxxxxxxx",//your device token
                Payload = JObject.Parse("{'aps':{'badge':1,'sound':'oven.caf','alert':'" + message + "'}}")
            });

            ServiceBroker.Stop();
        }

No comments:

Post a Comment

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...