推送通知 - 错误 - 缺少注册
Posted
技术标签:
【中文标题】推送通知 - 错误 - 缺少注册【英文标题】:Push notifications -Error - Missing Registration 【发布时间】:2013-05-06 05:36:18 【问题描述】:我已通过 GCM 使用 ASP.net C# 向安卓手机发送推送通知。
但我尝试了不同类型的代码,但所有 arr 都返回 Missing Registration 错误,所以请帮助我。
【问题讨论】:
你能发布你的代码吗? 【参考方案1】:试试PushSharp。这很简单。 并检查此说明 - How to Configure & Send GCM Google Cloud Messaging Push Notifications using PushSharp
var push = new PushBroker();
//Registering the GCM Service and sending an android Notification
push.RegisterGcmService(new GcmPushChannelSettings("theauthorizationtokenhere"));
//Fluent construction of an Android GCM Notification
//IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
.WithJson("\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\""));
您可以通过nuget安装它。
【讨论】:
我正在使用此代码。 codeproject.com/Tips/434338/Android-GCM-Push-Notification。你能这样推荐吗 @user2353494 你的手机支持GCM吗?您在这部手机上有 Google 帐户吗? 亚德米特里我有。或者你能不能把pushsharp配置到我的asp.net web应用程序中。在那一点上我很挣扎,因为我使用的是框架 2.0。 @user2353494 我希望您指的是 PushSharp 2.0,而不是 .NET 2.0。只需从 nuget 安装软件包 - nuget.org/packages/PushSharp,然后按照那里的说明进行操作 - github.com/Redth/PushSharp(示例代码)。我会更新答案。 嗨,dimi,我试过了,但它仍然抛出了一些异常。但是你能从 codeproject codeproject.com/Tips/434338/Android-GCM-Push-Notification 抛出上面的代码吗?告诉它为什么会发生,请哥们...... :)【参考方案2】: public class GCMSNS
public static string SendGCMNotification(string deviceId, string message)
string GoogleAppID = "XYxxxxxxxxxxxxxxxxxxxx";//This is API Key Server
var SENDER_ID = "11111111111111"; //This is Google Project Id
var value = message;
WebRequest tRequest;
tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key=0", GoogleAppID));
tRequest.Headers.Add(string.Format("Sender: id=0", SENDER_ID));
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" +
System.DateTime.Now.ToString() + "®istration_id=" + deviceId + "";
Console.WriteLine(postData);
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd();
tReader.Close();
dataStream.Close();
tResponse.Close();
return sResponseFromServer;
【讨论】:
以上是关于推送通知 - 错误 - 缺少注册的主要内容,如果未能解决你的问题,请参考以下文章