Monday, December 23, 2013

Nuget Package for Push Notification on Android and iOS

Continue to my previous post for Push Notification, I have generated a simplified process to implement Push notification for iOS and Android.

Anyone can download my Nuget package from https://www.nuget.org/packages/EasyPushNotification/

To install Push Notification for Android and iOS, run the following command in the Package Manager Console
PM> Install-Package EasyPushNotification

Web.config settings

Add following keys into AppSettings into web.config file.

<appSettings>
        <add key="APIKey" value="SOME_API_KEY"/>
        <add key="ApnsCertPath" value="CERTIFICATE_PATH"/>
        <add key="ApnsCertPassword" value="CERT_PASSWORD"/>
</appSettings>



For Android
APIKey    is API key provided by GCM server. Follow the steps from here to generate project and obtain API key. The generated Project ID will be used to generate Device Token from Android devices.
For iOS
ApnsCertPath is the physical path where iOS apns certificate is stored. This should be a located into server and the path should be something like "~/Certificate_Folder/Certificate_Name.p12” follow the steps from here to generate certificate. (iOS developer might have better ideas how to generate certificate.)


ApnsCertPassword is password for certificate generate from above step.

Call Method

Use below code block to raise push notification.
string DeviceID = string.Empty;
string Message = string.Empty;
DeviceType DeviceType = DeviceType.Android;

NotificationInfo objNotificationInfo = new NotificationInfo();
bool result = objNotificationInfo.SendNotification(DeviceID, Message, DeviceType);


Parameters:
                DeviceID is Device token generate using phone and stored into database table using a service call. 
                Message is string variable. The message is to be displayed as notification.
                DeviceType is an Enum variable to decide whether the device is Android or iOS device. Fetch Device type from database which as stored with DeviceToken using service.
Returns:
Method will return Boolean result as success or failed.
ProcessResult will provide handled exception message.

isError is Boolean variable to indicate any error occurs.

Happy Mobilizing.. 
Post a Comment