Android推送上的通知失败(注册无效)

时间:2015-06-02 14:56:55

标签: c# android google-cloud-messaging push pushsharp

我已成功向iOS设备发送推送消息,但我遇到了Android问题。我收到了GCM API密钥和安装了该应用程序的设备的注册ID。

但是,当我尝试发送推送消息时,会触发NotificationFailed事件。我得到的例外是PushSharp.Android.GcmMessageTransportResponse类型,其消息是"无效注册"。我做错了什么?

var push = new PushBroker();
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("AIXXXXXXXXXXXXXXXX"));
push.QueueNotification(new GcmNotification()
             .ForDeviceRegistrationId("APAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}");
push.StopAllServices();

2 个答案:

答案 0 :(得分:1)

针对Android推送通知需要Google API密钥,可以在Google API控制台中找到,我认为您已经拥有该密钥。

您的设备注册ID很可能不正确。 请尝试按照以下说明操作:How to configure and send GCM push notification

答案 1 :(得分:1)

这绝对是API关键问题。检查您从Developers Console获得的API密钥。它通常以“AIza ......”开头

GCM文档here中提到了这个确切的错误。