Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:03:25+00:00 2026-06-17T05:03:25+00:00

I am completely New to Apple Push Notifications service. I am trying to implement

  • 0

I am completely New to Apple Push Notifications service. I am trying to implement it for my applications. I searched well in google as well as in stackoverflow, but not satisfied. I am trying to implement provider in c#. I have tried MoonAPNs too.

Can anybody here suggest me good step by step tutorial on it that is very simple. I have already obtained ios developer and apn certificates as well as p12 key. I need help then on.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:03:27+00:00Added an answer on June 17, 2026 at 5:03 am

    Here is the infrastructure and process I am using:

    Brief Overview:
    I use PushSharp for communicating with the APNS servers. I have a SQL Server backend DB setup to handle all the subscriptions and notifications that get sent. I also have a virtual server (several actually) that all have the .p12 certs copied to them. These servers have process that checks the table for any push notifications that need to go out and then pass the dataset along to the PushSharp process.

    Detailed Specs:
    Table 1 – APNS_Subscriptions

    CREATE TABLE [dbo].[APNS_Subscriptions](
        [id] [int] IDENTITY(1,1) NOT NULL,
        [DeviceToken] [varchar](250) NULL,
        [DeviceID] [varchar](250) NULL,
        [NetworkID] [varchar](250) NULL,
        [Application] [varchar](250) NULL,
        [AddedOn] [datetime] NULL,
        [Active] [bit] NULL,
        [Dev] [bit] NULL,
        [BadgeCount] [int] NOT NULL,
     CONSTRAINT [PK_APNSSubscriptions] PRIMARY KEY CLUSTERED 
    (
        [id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    

    Table 2 – APNS_PushNotifications

    CREATE TABLE [dbo].[APNS_PushNotifications](
        [id] [int] IDENTITY(1,1) NOT NULL,
        [DeviceToken] [varchar](250) NULL,
        [AlertMessage] [varchar](250) NULL,
        [BadgeNumber] [int] NULL,
        [SoundFile] [varchar](250) NULL,
        [ApplicationName] [varchar](250) NULL,
        [AddedOn] [datetime] NULL,
        [AddedBy] [varchar](250) NULL,
        [ProcessedOn] [datetime] NULL,
        [ViewedOnDeviceDateTime] [datetime] NULL,
     CONSTRAINT [PK_APNS_PushNotifications] PRIMARY KEY CLUSTERED 
    (
        [id] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    

    I add subscriptions via this SP (this is called through a webservice via each iPhone app that implements APNS:

    [ins_APNS_Sub]
        @MyDeviceID VARCHAR(250) ,
        @MyDeviceToken VARCHAR(250) ,
        @MyApplicationName VARCHAR(250)
    AS 
        DECLARE @Count AS INT
    
        SET @Count = ( SELECT   COUNT(id)
                       FROM     dbo.APNS_Subscriptions
                       WHERE    DeviceID = @MyDeviceID
                                AND DeviceToken = @MyDeviceToken
                                AND [Application] = @MyApplicationName
                     )
    
        IF @Count = 0 
            BEGIN
                DECLARE @NetworkID AS VARCHAR(250)
                SET @NetworkID = ( SELECT TOP 1
                                            networkid
                                   FROM     dbo.AuthenticatedDevices
                                   WHERE    deviceid = @MyDeviceID
                                            AND COALESCE(banned, 0) = 0
                                   ORDER BY lastupdatedon DESC
                                 )
    
                IF @NetworkID IS NOT NULL 
                    BEGIN
    
                        INSERT  INTO dbo.APNS_Subscriptions
                                ( DeviceToken ,
                                  DeviceID ,
                                  NetworkID ,
                                  [Application] ,
                                  AddedOn ,
                                  Active
                                )
                        VALUES  ( @MyDeviceToken , -- DeviceToken - varchar(250)
                                  @MyDeviceID , -- DeviceID - varchar(250)
                                  @NetworkID , -- NetworkID - varchar(250)
                                  @MyApplicationName , -- Application - varchar(250)
                                  CURRENT_TIMESTAMP , -- AddedOn - datetime
                                  1  -- Active - bit
                                )
                    END
            END
    

    Push Notifications are added via this SP:

    [ins_APNS_PushNote]
        @MyNetworkID VARCHAR(250) ,  -- NetworkID of recipient or ALL to go to all recipients
        @MyApplicationName VARCHAR(250) ,  -- Application Name for the iOS app
        @APNSAlertMessage VARCHAR(225) , -- Alert Message (Required)
        @APNSSoundFile VARCHAR(250) = NULL ,
        @WhoRequested VARCHAR(250) -- Process Name that called this SP
    AS 
    
    
       -- Get the current badge count, make a temp table and increment the appropriate rows in the Sub table
        DECLARE @UpdateTable AS TABLE
            (
              DeviceToken VARCHAR(250) ,
              NetworkID VARCHAR(250) ,
              ApplicationName VARCHAR(250) ,
              BadgeCount INT
            )
    
        IF @MyNetworkID = 'ALL' 
            BEGIN
    
                INSERT  INTO @UpdateTable
                        ( DeviceToken ,
                          NetworkID ,
                          ApplicationName ,
                          BadgeCount
                        )
                        SELECT  DeviceToken ,
                                NetworkID ,
                                [Application] ,
                                BadgeCount
                        FROM    dbo.APNS_Subscriptions
                        WHERE   [Application] = @MyApplicationName
                                AND COALESCE(Dev, 0) = 0
    
                UPDATE  @UpdateTable
                SET     BadgeCount = BadgeCount + 1
    
                UPDATE  sub
                SET     sub.BadgeCount = temp.BadgeCount
                FROM    dbo.APNS_Subscriptions sub
                        INNER JOIN @UpdateTable temp ON temp.DeviceToken = sub.DeviceToken
                                                        AND temp.NetworkID = sub.NetworkID
                                                        AND temp.ApplicationName = sub.[Application]
    
                INSERT  INTO dbo.APNS_PushNotifications
                        ( DeviceToken ,
                          AlertMessage ,
                          BadgeNumber ,
                          SoundFile ,
                          ApplicationName ,
                          AddedOn ,
                          AddedBy
    
                        )
                        SELECT  sub.DeviceToken ,
                                @APNSAlertMessage ,
                                temp.BadgeCount ,
                                @APNSSoundFile ,
                                @MyApplicationName ,
                                CURRENT_TIMESTAMP ,
                                @WhoRequested
                        FROM    dbo.APNS_Subscriptions sub
                                INNER JOIN dbo.AuthenticatedDevices ad ON ad.deviceid = sub.DeviceID
                                INNER JOIN @UpdateTable temp ON temp.DeviceToken = sub.DeviceToken
                                                                AND temp.ApplicationName = sub.[Application]
                        WHERE   COALESCE(ad.banned, 0) = 0
                                AND sub.[Application] = @MyApplicationName
                                  --  AND ad.networkid = @MyNetworkID
                                AND COALESCE(sub.Dev, 0) = 0
            END    
        ELSE 
            BEGIN
    
                DECLARE @Count AS INT = ( SELECT    COUNT(id)
                                          FROM      dbo.APNS_Subscriptions
                                          WHERE     NetworkID = @MyNetworkID
                                                    AND Active = 1
                                                    AND [Application] = @MyApplicationName
                                        )
    
    
                IF @Count = 0 
                    BEGIN
                        RETURN
                    END     
    
                INSERT  INTO @UpdateTable
                        ( DeviceToken ,
                          NetworkID ,
                          ApplicationName ,
                          BadgeCount
                        )
                        SELECT  DeviceToken ,
                                NetworkID ,
                                [Application] ,
                                BadgeCount
                        FROM    dbo.APNS_Subscriptions
                        WHERE   [Application] = @MyApplicationName
                                AND COALESCE(Dev, 0) = 0
                                AND NetworkID = @MyNetworkID
    
                UPDATE  @UpdateTable
                SET     BadgeCount = BadgeCount + 1
    
                UPDATE  sub
                SET     sub.BadgeCount = temp.BadgeCount
                FROM    dbo.APNS_Subscriptions sub
                        INNER JOIN @UpdateTable temp ON temp.DeviceToken = sub.DeviceToken
                                                        AND temp.NetworkID = sub.NetworkID
                                                        AND temp.ApplicationName = sub.[Application]
    
                INSERT  INTO dbo.APNS_PushNotifications
                        ( DeviceToken ,
                          AlertMessage ,
                          BadgeNumber ,
                          SoundFile ,
                          ApplicationName ,
                          AddedOn ,
                          AddedBy
    
                        )
                        SELECT  sub.DeviceToken ,
                                @APNSAlertMessage ,
                                temp.BadgeCount ,
                                @APNSSoundFile ,
                                @MyApplicationName ,
                                CURRENT_TIMESTAMP ,
                                @WhoRequested
                        FROM    dbo.APNS_Subscriptions sub
                                INNER JOIN dbo.AuthenticatedDevices ad ON ad.deviceid = sub.DeviceID
                                INNER JOIN @UpdateTable temp ON temp.DeviceToken = sub.DeviceToken
                                                                AND temp.ApplicationName = sub.[Application]
                        WHERE   COALESCE(ad.banned, 0) = 0
                                AND sub.[Application] = @MyApplicationName
                                AND sub.networkid = @MyNetworkID
                                AND COALESCE(sub.Dev, 0) = 0
                                AND COALESCE(sub.Active, 0) = 1
    
            END   
    

    This is called from several different places in several different DB’s this way:
    EXECUTE [ins_APNS_PushNote]
    @NetworkID
    ,@iOSApplicationName
    ,@AlertMessage
    ,@SoundFile
    ,@RequestedBy

    The SP that retrieves these APNS requests for the virtual server (PushSharp):

    [get_APNSToSend]
    AS 
        BEGIN
    
            DECLARE @CurrentTimestamp AS DATETIME = CURRENT_TIMESTAMP
    
            UPDATE dbo.APNS_PushNotifications
            SET ProcessedOn = CURRENT_TIMESTAMP
            WHERE ProcessedOn IS NULL
    
            SELECT  id ,
                    DeviceToken ,
                    AlertMessage ,
                    BadgeNumber ,
                    SoundFile ,
                    ai.APNSDistCertFile AS APNSCertFile
            FROM    dbo.APNS_PushNotifications apns
                    INNER JOIN dbo.ApplicationInfo ai ON ai.ApplicationName = apns.ApplicationName
            WHERE   ProcessedOn = @CurrentTimestamp
                    AND ai.APNSDistCertFile IS NOT NULL
    
    
        END 
    

    Now for the changes I made to the PushSharp app. Really just boils down to two methods:
    static void Main(string[] args)
    {
    checkForPushRequest();
    }

        static void checkForPushRequest()
        {
            string YourConnString = "YourConnectionStringToTheDBGoesHere";
    
                Stored_Procedure SP = new Stored_Procedure {
                Name = "get_APNSToSend",
                Parameters = new List<SqlParameter>()
            };
    
            try {
                System.Data.DataTable dt = DatabaseOperations.Execute_Database_Command(YourConnString, SP, true);
    
                if ((dt != null) && !(dt.Rows.Count < 1)) {
                    foreach (System.Data.DataRow dRow in dt.Rows) {
                        string deviceToken = Convert.ToString(dRow[1]);
                        string alertMessage = Convert.ToString(dRow[2]);
                        int badgeNumber =  Convert.ToInt16(dRow[3]);
                        string soundFile = Convert.ToString(dRow[4]);
                        string apnsCertFileToUse = Convert.ToString(dRow[5]);
                        sendPush(deviceToken, alertMessage, soundFile, badgeNumber, apnsCertFileToUse);
                    }
                }
            } catch (Exception ex) {
                // Handle your exception
            }
        }
    
        static void sendPush(string DeviceToken, string AlertMessage, string SoundFile, int BadgeNumber, string apnsCertFileToUse)
        {
            //Create our service    
            PushService push = new PushService();
    
            //Wire up the events
            push.Events.OnDeviceSubscriptionExpired += new PushSharp.Common.ChannelEvents.DeviceSubscriptionExpired(Events_OnDeviceSubscriptionExpired);
            //push.Events.OnDeviceSubscriptionIdChanged += new PushSharp.Common.ChannelEvents.DeviceSubscriptionIdChanged(Events_OnDeviceSubscriptionIdChanged);
            push.Events.OnChannelException += new PushSharp.Common.ChannelEvents.ChannelExceptionDelegate(Events_OnChannelException);
            push.Events.OnNotificationSendFailure += new PushSharp.Common.ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
            push.Events.OnNotificationSent += new PushSharp.Common.ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
    
            //Configure and start Apple APNS
            // IMPORTANT: Make sure you use the right Push certificate.  Apple allows you to generate one for connecting to Sandbox,
            //   and one for connecting to Production.  You must use the right one, to match the provisioning profile you build your
            //   app with!  
            //  This comes from the ApplicationInfo table.  Each app that supports APNS has it's own certfile name in the column
            string certFileToUse = "C:\\APNS_Certs\\" + apnsCertFileToUse;
    
            var appleCert = File.ReadAllBytes(certFileToUse);
    
            //IMPORTANT: If you are using a Development provisioning Profile, you must use the Sandbox push notification server 
            //  (so you would leave the first arg in the ctor of ApplePushChannelSettings as 'false')
            //  If you are using an AdHoc or AppStore provisioning profile, you must use the Production push notification server
            //  (so you would change the first arg in the ctor of ApplePushChannelSettings to 'true')
            push.StartApplePushService(new ApplePushChannelSettings(false, appleCert, "P12PasswordHere"));
    
            //Fluent construction of an iOS notification
            //IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate
            //  for registered for remote notifications is called, and the device token is passed back to you
            push.QueueNotification(NotificationFactory.Apple()
                .ForDeviceToken(DeviceToken)
                .WithAlert(AlertMessage)
                .WithSound(SoundFile)
                .WithBadge(BadgeNumber));
    
            //Console.WriteLine("Waiting for Queue to Finish...");
    
            //Stop and wait for the queues to drains
            push.StopAllServices(true);
    
           // Console.WriteLine("Queue Finished, press return to exit...");         
        }
    

    I added a Console project to the PushSharp solution and deployed the Console to the APNS server. This console app is fired based on scheduled task to run every minute.

    If you have more questions, let me know. I have been using this process for the last year in an enterprise environment and have had no issues. Works flawlessly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to javascript, but I'm trying to create a beta form for
Completely new to most of this stuff, but basically Im playing around with the
I am Completely new to Objective C and Cocoa programming. Why does NSApplicationMain not
Completely new to Objective-C, trying to find out when I need to alloc and
I think this is a new spin on an old question, but I'm completely
I'm completely new to SQL, and have read StackOverflow posts on SQL to try
I'm trying to build a application for the iPhone, although I am completely new
so I am completely new to jquery and am trying to figure out how
I'm completely new to HTML, CSS and Javascript but drawing on previous knowledge of
Completely new to asp.net mvc... completely new to web apps so bear with me...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.