내 서버에서 푸시 알림을 최적화하려고합니다. 지금은 그 중 하나를 하나씩 보내고 (오래된 도서관에서), 시간이 좀 걸립니다 (4 시간).하나 이상의 기기 (iOS)에 푸시 알림을 보내는 방법은 무엇입니까?
많은 서비스 토큰을 사용하여 알림을 보내도록 리팩터링했습니다 (지금은 500 개의 토큰을 사용했습니다). 이를 위해 Redth/PushSharp 라이브러리를 사용하고 있습니다. 나는 sample code을 따랐다. 그리고 나는 그것을 severals 장치 토큰에 통지하기 위해 채택했다.
PushService service = new PushService();
//Wire up the events
service.Events.OnDeviceSubscriptionExpired += new PushSharp.Common.ChannelEvents.DeviceSubscriptionExpired(Events_OnDeviceSubscriptionExpired);
service.Events.OnDeviceSubscriptionIdChanged += new PushSharp.Common.ChannelEvents.DeviceSubscriptionIdChanged(Events_OnDeviceSubscriptionIdChanged);
service.Events.OnChannelException += new PushSharp.Common.ChannelEvents.ChannelExceptionDelegate(Events_OnChannelException);
service.Events.OnNotificationSendFailure += new PushSharp.Common.ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
service.Events.OnNotificationSent += new PushSharp.Common.ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
service.Events.OnChannelCreated += new PushSharp.Common.ChannelEvents.ChannelCreatedDelegate(Events_OnChannelCreated);
service.Events.OnChannelDestroyed += new PushSharp.Common.ChannelEvents.ChannelDestroyedDelegate(Events_OnChannelDestroyed);
//Configure and start ApplePushNotificationService
string p12Filename = ...
string p12FilePassword = ...
var appleCert = File.ReadAllBytes(p12Filename);
service.StartApplePushService(new ApplePushChannelSettings(true, appleCert, p12FilePassword));
var appleNotification = NotificationFactory.Apple();
foreach (var itemToProcess in itemsToProcess)
{
itemToProcess.NotificationDateTime = DateTime.Now;
mobile.SubmitChanges();
string deviceToken = GetCleanDeviceToken(itemToProcess.MobileDevice.PushNotificationIdentifier);
appleNotification.ForDeviceToken(deviceToken);
}
service.QueueNotification(appleNotification
.WithAlert(itemsToProcess[0].MobileDeviceNotificationText.Text)
.WithSound("default")
.WithBadge(0)
.WithCustomItem("View", itemsToProcess[0].Value.ToString()));
//Stop and wait for the queues to drains
service.StopAllServices(true);
그런 다음 2 개의 기기에 3 개의 알림을 보냈습니다. 첫 번째 장치 만 가져 왔고 (문제는 두 장치를 따로 따로 시도했기 때문에 장치 관련이 아닙니다.) 바로 뒤에 PushChannelBase class에 OperationCanceledException이 발생합니다. 그래서 나는 무엇이 잘못되었는지를 모른다. 어떤 생각?
안녕하세요. 단일 요청으로 단일 장치를 여러 장치에 보낼 수 있습니다. 나는 r & d를 수행하고 코드를 구현하고 5-10 개의 장치로 테스트했습니다. –