Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hope this is relevant (slightly), but I have just successfully created one for Java, so conceptually quite similar to C# (except perhaps the SSL stuff, but that shouldn't be too hard to modify. Below is a sample message payload and crypto setup:</p> <pre><code> int port = 2195; String hostname = "gateway.sandbox.push.apple.com"; char []passwKey = "&lt;keystorePassword&gt;".toCharArray(); KeyStore ts = KeyStore.getInstance("PKCS12"); ts.load(new FileInputStream("/path/to/apn_keystore/cert.p12"), passwKey); KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509"); tmf.init(ts,passwKey); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(tmf.getKeyManagers(), null, null); SSLSocketFactory factory =sslContext.getSocketFactory(); SSLSocket socket = (SSLSocket) factory.createSocket(hostname,port); // Create the ServerSocket String[] suites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(suites); //start handshake socket.startHandshake(); // Create streams to securely send and receive data to the server InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); // Read from in and write to out... ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(0); //The command System.out.println("First byte Current size: " + baos.size()); baos.write(0); //The first byte of the deviceId length baos.write(32); //The deviceId length System.out.println("Second byte Current size: " + baos.size()); String deviceId = "&lt;heaxdecimal representation of deviceId"; baos.write(hexStringToByteArray(deviceId.toUpperCase())); System.out.println("Device ID: Current size: " + baos.size()); String payload = "{\"aps\":{\"alert\":\"I like spoons also\",\"badge\":14}}"; System.out.println("Sending payload: " + payload); baos.write(0); //First byte of payload length; baos.write(payload.length()); baos.write(payload.getBytes()); out.write(baos.toByteArray()); out.flush(); System.out.println("Closing socket.."); // Close the socket in.close(); out.close(); </code></pre> <p>}</p> <p>Once again, not C#, but at least closer than the poor ObjC sample that Apple provides.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload