我需要將通知推送到我的應用安裝的數以萬計的iOS設備。我試圖用PushSharp來做,但我在這裏錯過了一些基本概念。起初我試圖在Windows服務中實際運行它,但無法使它工作 - 從_push.QueueNotification()調用中獲得空引用錯誤。然後我做了記錄的示例代碼做了什麼和它的工作:PushSharp推送通知 - 基礎知識
PushService _push = new PushService();
_push.Events.OnNotificationSendFailure += new ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
_push.Events.OnNotificationSent += new ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
var cert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("..pathtokeyfile.p12"));
_push.StartApplePushService(new ApplePushChannelSettings(false, cert, "certpwd"));
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
_push.QueueNotification(notification);
_push.StopAllServices(true);
問題#1: 這工作完全和我看到通知上彈出iPhone。然而,因爲它被稱爲推送服務,我認爲它會像服務一樣 - 也就是說,我實例化它並在Windows服務中調用_push.StartApplePushService()。我認爲其實排隊我通知,我能做到這一點的前端(管理應用程序,比方說):
PushService push = new PushService();
AppleNotification notification = NotificationFactory.Apple()
.ForDeviceToken(deviceToken)
.WithAlert(message)
.WithSound("default")
.WithBadge(badge);
push.QueueNotification(notification);
顯然,(就像我已經說過的),它沒有工作 - 最後一行不斷拋出空引用異常。
我很難找到任何其他類型的文檔,以顯示如何以服務/客戶端方式設置(而不是一次調用所有內容)。是否有可能或缺少應該如何使用PushSharp的要點?
問題#2: 另外,我似乎無法找到一種方法,針對一次設備多令牌,而無需通過他們循環,每次排隊通知之一。這是唯一的方法還是我在這裏錯過了一些東西?
在此先感謝。
我在'NotificationFactory'和'PushService'下不斷收到一條紅線,我缺少一些東西可以包含嗎? – 2014-04-15 14:37:17
您正在使用哪種PushSharp版本?> – Lakshay