Sunday, 10 September 2017

IOS Push Notification in C# using PushSharp


Here we learn more about sending notification through PushSharp in IOS devices using C#.

PushSharp is a server-side library which can use for sending Push Notification to IOS, Android devices(using Google Cloud Messaging), Windows phones and Blackberry devices.

PushSharp is a library which you can download from below link or you can also use this through NuGet packages.

https://github.com/Redth/PushSharp

It's very easy to use and very easy to install for IOS, Android, Windows and Blackberry devices.

To use this library to send notification in IOS devices, first of all, you need to create .p12 certificate file which is very easy to create in Mac

Below are the steps for your reference.

  1. Login to your IOS development center by using this address: https://developer.apple.com/devcenter/ios then click on "Certificates, Identifiers & Profiles".
  2. When you click on it one IOS Apps will open, which contains four options like Certificates, Identifiers, Devices and Provisioning Profiles, So please click on Identifiers.
  3. When you click on Identifiers IOS App ID's wizard will open and select your Application ID which you previously created for your application. In that screen click on edit button to make changes.
  4. When you click new wizard will open and that wizard has Push Notifications check box, So click on it and it will display Development SSL Certificate & Production SSL Certificate options. After this click on create certificates under Production SSL Certificate and click continue.
  5. After this click on "Choose File" button and select CSR (Certificate Signing Request) file and click on generate.
  6. Click on "Download" button to download your Push Notification Certificate and then click on done.
To follow above process you will easily create Certificate file in Mac system.

How to convert Push Notification Certificate as a .p12 File

  1. Go to Keychain Access and select your certificate which you have installed in Keychain Access previously then right click on it and click on "Export".
  2. When you click on export wizard will open which contains four options Save As, Tags, Where and File Format, provide certificate name as per your requirement in Save As box, provide location where you want to save your file in Where box, make sure the File Format is set to "Personal Information Exchange" (.p12) click on save button to save it to your system.
  3. If it will ask for password leave it blank and click on Ok button.
  4. If it will ask for company password so enter it and click on Allow button.
  5. Then your .p12 file is ready and saved in the location which you specified.

If you follow above procedure correctly so your "Personal Information Exchange" (.p12) file is ready to use in our C# code.


use below code in C# to send Push Notification in IOS devices using PushSharp library.

#put your certificate file in configuration section so it will read and create a configuration#
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, Server.MapPath("AppCertificate/Certificate.p12"), "", true);

#Intialize ApnsServiceBroker to provide ApnsConfiguration#
var apnsBroker = new ApnsServiceBroker(config);

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;                   
                if (ex.InnerException != null) {
                       Response.Write(ex.InnerException.ToString());
                 }

#Deal with the failed notification#
                var apnsNotification = notificationException.Notification;
                var statusCode = notificationException.ErrorStatusCode;
                Response.Write("Apple Notification Failed: ID= " + apnsNotification.Identifier + ",                             Code=" + statusCode);
             }
             else {
#Inner exception might hold more useful information like an ApnsConnectionException#
                     Response.Write("Notification Failed for some unknown reason : " + ex.InnerException);
              }
# Mark it as handled#
                    return true;
    });
};

apnsBroker.OnNotificationSucceeded += (notification) =>
{
     Response.Write("Apple Notification Sent!");
 };
 #Start the broker#
apnsBroker.Start();
#Queue a notification to send#
apnsBroker.QueueNotification(new ApnsNotification
{
    DeviceToken = #Registration_Id#,
    Payload = JObject.Parse("{\"aps\":{\"alert\":\"" + Server.HtmlEncode(description) + 
                                                        "\",\"badge\":\"" + 5 + "\",\"sound\":\"noti.aiff\"}}")
                                              });

#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();
 }

Here we finished it up with coding part if you follow each and every step correctly so you are able to send Push Notification in IOS devices using PushSharp.

Let us know if I miss anything above. Put your comments below related to any queries or any topic related to .Net, Android.

KEEP CALM & READ ON!!!

Monday, 12 June 2017

Play with jQuery Reel


jQuery reel is the most versatile three-sixty player for jQuery. By using this you can put animations to your images, rotates your images up to 360° it provides so many functionalities like responsiveness, panorama etc by using reel you can avoid Flash, Java.

The biggest advantage of using reel is there is no need to use Flash into your website you just need to use reel and images it completes your work and it provides 50+ customization
fully supports to browsers, mobiles and touch devices.
  • It covers beyond 360 rotation.
  • Animated rotations.
  • Support both mouse and touch. 
  • 50+ option for customization.
  • Mobile device support (you just need to do some settings for this.) 
  • Flash free (By using images it will give you full video experience.)
  • It requires only jQuery nothing else.
  • It is free and open source so you have full hand over it.
There are two ways to implement this by using HTML and java-script with reel js. Here is the link where you can download the latest version of the reel.

First implementation by using HTML 


1. Add a reference to jquery.reel.js to your document.

2. Add class reel to your HTML tag and provide below settings as data attributes.


reel


providing these options to your image can trigger reel.

There are so many attributes are present in reel dictionary below is a link where you can use those options and customize your application.


Second implementation by using Javascript and HTML


1. Add a reference to jquery.reel.js to your document.

2. Add image tag into your HTML and provide Id, src, width and height.



3. Add below java-script code to your HTML to work with the reel.




By adding above code into your HTML will trigger jquery.reel.js and it will start you image rotation and gives full 360 visualizations. 

You can learn more about reel by visiting this URL.

For examples please visit this jquery-reel-examples.


If you have any query or suggestion, So I'll be happy to help you.

KEEP CALM and READ ON!!!!.
Ankur Omar