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:
private void SendPushNotifications(DataTable tblToPush)
{
string szSandbox = "";
string szFile ="";
string szPassword ="";
szSandbox = NGlobal.fnGetConfig("sandbox");
szFile = NGlobal.fnGetConfig("p12File");
szPassword = NGlobal.fnGetConfig("p12FilePassword");
bool sandbox = true;
if (szSandbox == "1")
{
sandbox = false;
}
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;
service.ReconnectDelay = 5000;
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();
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:
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