우리는 사과 푸시 알림 서비스를 사용하고 있으며 우리는 gateway.sandbox.push.apple.com의 푸시 메시지를 보낼 수 있습니다.이 주소는 테스트이므로 모두 실제 주소 게이트웨이를 사용해야합니다. .push.apple.com,이 주소에서 푸시 메시지를 보낼 수 없습니다. 우리를 도울 수 있니?아이폰 푸시 알림 C에서 #
코드는 다음과 같습니다.
public void pushMessage(string deviceID, string Mesaj)
{
int port = 2195;
String hostname = "gateway.sandbox.push.apple.com"; // TEST
//String hostname = "gateway.push.apple.com"; // REAL
// @"cert.p12";
String certificatePath = HttpContext.Current.Server.MapPath("cert.p12");
//X509Certificate2 clientCertificate = new X509Certificate2(certificatePath, "");
X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, true);
}
catch (Exception e)
{
throw (e);
client.Close();
return;
}
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0); //The command
writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte)
writer.Write((byte)32); //The deviceId length (big-endian second byte)
writer.Write(HexStringToByteArray(deviceID.ToUpper()));
String payload = "{\"aps\":{\"alert\":\"" + Mesaj + "\",\"badge\":0,\"sound\":\"default\"}}";
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();
}
당신은 당신이 잘 애플에 정보를 보낼 수 있습니다처럼 소리 문제
정확히 작동하지 않는 기능은 무엇입니까? 어떤 종류의 오류 메시지가 나타 납니까? – R0MANARMY
이 http://stackoverflow.com/questions/2319337/cant-connect-to-production-apple-push-notification-server – Darkface35
우리는 오류 메시지를받을 수 없습니다보십시오. gateway.sandbox.push.apple.com에서 알림을 보낼 수 있지만 gateway.push.apple.com에서 보낼 수 없습니다. – cdsoft