我最近实施了PushSharp到一个应用程序,但对于我的生活我无法弄清楚为什么通知没有出现在设备上。PushSharp GCM消息传递
以下是放在一起测试行为的方法:
private void SendPushNotification()
{
var push = new PushBroker();
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
push.RegisterGcmService(new GcmPushChannelSettings("My-API-Key-here"));
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("MyReallyLongRegisteredDeviceKeyHere")
.WithJson(@"{""alert"":""Hello World!"",""badge"":7,""sound"":""sound.caf""}"));
//Stop and wait for the queues to drains
push.StopAllServices();
}
这种方法在应用程序启动立即打电话,所以我希望我得到通知马上,我不知道。
还有什么奇怪的是,事件OnNotificationSent
被调用,这将表明消息已经通过。
还有什么我需要配置为了这个工作?该文件指出,发件人ID,包名和API密钥,需要以发送通知
所有,但API密钥,虽然使用。
任何帮助将不胜感激。
您是否已将包名更改为您的包名?例如,BroadcastReceiver。 – ztan 2015-02-11 17:30:02
您是指服务器还是应用程序?如上所述,我看不到任何文件,这将表明我需要更新包名 – 2015-02-11 22:27:35
从这个页面:https://github.com/Redth/PushSharp'看看PushService.cs文件中示例项目。您可以将大部分此类复制到您自己的应用程序中,但同样要确保在适用的情况下(您需要更改BroadcastReceiver属性)替换您自己的软件包名称。 ' – ztan 2015-02-11 22:34:00