Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using c# and vb.net to send push notifications for apple and blackberry handsets, but my app sends for only 1 user at a time, so i need to get a new method to send a push notification to several users at the same time...

here is the code i'm using:

apple:

C#
private void SendPushNotifications(DataTable tblToPush)
           {

       //True if you are using sandbox certificate, or false if using production
       string szSandbox = "";
       string szFile  ="";
       string szPassword   ="";
       szSandbox = NGlobal.fnGetConfig("sandbox");
       szFile = NGlobal.fnGetConfig("p12File");
       szPassword = NGlobal.fnGetConfig("p12FilePassword");

       bool sandbox = true; //dev
       if (szSandbox == "1")
       {
            sandbox = false; //prod
       }

       string p12File = szFile;
       string p12FilePassword = szPassword;
       string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);

       NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword,1);

       service.SendRetries = 5; //5 retries before generating notificationfailed event
       service.ReconnectDelay = 5000; //5 seconds

       service.Error += new NotificationService.OnError(service_Error);
       service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);

       service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
       service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
       service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
       service.Connecting += new NotificationService.OnConnecting(service_Connecting);
       service.Connected += new NotificationService.OnConnected(service_Connected);
       service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
 }

  public bool PushMessage(string testDeviceToken, string message, NotificationService service, int i, string szHiddenMessage)
   {
       var payload1 =new NotificationPayload();

           //Create a new notification to send
           Notification alertNotification = new Notification(testDeviceToken);

           if (szHiddenMessage == "startAlarm")
           {
               payload1 = new NotificationPayload(message, 0, "alarm.m4a");
           }
           else{
               if (szHiddenMessage == "wipeDevice" ||  szHiddenMessage == "sendLocation")
                {
                    payload1 = new NotificationPayload(message, 0, "Silence.m4r");
               }

               else{

                    payload1 = new NotificationPayload(message, 1, "Default");

               }
           }
           payload1.AddCustom("message", szHiddenMessage);

           var push = new Notification(testDeviceToken, payload1);
            }

blackberry:

VB
SyncLock lockThis
       If szPinCode <> "" AndAlso szPinCode <> "" Then
           Dim BBPushRequest As New HttpBBPushRequest(szPinCode, szMessage, szId, Me)
           BBPushRequest.Url = general.fnGetConfig("PUSH_URL")
           BBPushRequest.ApplicationID = general.fnGetConfig("PUSH_APPLICATIONID")
           BBPushRequest.UserName = general.fnGetConfig("PUSH_USERNAME")
           BBPushRequest.UserPassword = general.fnGetConfig("PUSH_USERPASSWORD")
           Dim clientThread As New Thread(AddressOf BBPushRequest.Run)
           clientThread.Start()
           fnIncrementCounter()
           bResult = True
       End If
   End SyncLock
Posted
Comments
ZurdoDev 15-Apr-14 15:14pm    
Do these methods support sending to multiple users at a time? If not, just put them in a loop.
Jocelyne El Khoury 16-Apr-14 2:35am    
I don't want to use a loop because there will be delay between the push notifications i need to send all the notifications at the same time, so the devices get the push notifications at the same time without any delay

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900