c# - IOS推送通知未从c#收到
问题描述
我检查了这么多链接,我试过沙箱有主机名,也在本地计算机上安装了 .p12 文件。在这段代码完美运行之前。以及如何在发送推送通知时检查来自苹果的响应。代码按预期完美处理,但未收到推送通知。
try
{
int port = 2195;
String hostname = "gateway.push.apple.com";
//String certificatePath = "";
String certificatePath = HttpContext.Current.Server.MapPath("~/pushcert.pem");
X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "");
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, false);
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0);
writer.Write((byte)0);
writer.Write((byte)32);
var aps1 = new
{
alert = Subject,
messageId = "test",
type = type,
badge = 1,
sound = "default"
};
var aps = new
{
aps = aps1
};
var json = JsonConvert.SerializeObject(aps);
writer.Write(HexStringToByteArray(deviceID.ToUpper()));
String payload = json;
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
client.Close();
}
catch (System.Security.Authentication.AuthenticationException ex)
{
saveException(ex.Message, "Failed", "MobileAPI/SendMessage");
client.Close();
}
catch (Exception e)
{
saveException(e.Message, "Failed", "MobileAPI/SendMessage");
client.Close();
}
}
catch (Exception e)
{
saveException(e.Message, "Failed", "MobileAPI/SendMessage");
}
解决方案
推荐阅读
- python - 使用 Python 在 CSV 文件中搜索特定列
- python - 如何使用 python 使用 selenium 单击此链接?
- powershell - Powershell:在Switch语句中识别变量的名称
- node.js - 如何在没有 Firebase 的情况下使用 DialogFlow、node.js v2 库
- swift - Alamofire - 允许再次重定向
- java - 滥用 Optional#map 考虑缺席 Optional#peek 方法
- javascript - Chrome 扩展本机消息传递语法错误
- python - 带有 python 的 Onedrive API:路径和上传
- c# - 如何将参数传递给发布 URL C#
- python - 从文本文件中提取 IP 地址并将其用作 Python 中的输入