Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have you considered the <a href="http://twistedmatrix.com/trac/" rel="nofollow noreferrer">Twisted</a> package? The below code is taken from <a href="http://blog.nuclearbunny.org/2009/05/11/connecting-to-apple-push-notification-services-using-python-twisted/" rel="nofollow noreferrer">here</a>:</p> <pre><code>from struct import pack from OpenSSL import SSL from twisted.internet import reactor from twisted.internet.protocol import ClientFactory, Protocol from twisted.internet.ssl import ClientContextFactory APNS_SERVER_HOSTNAME = "&lt;insert the push hostname from your iPhone developer portal&gt;" APNS_SERVER_PORT = 2195 APNS_SSL_CERTIFICATE_FILE = "&lt;your ssl certificate.pem&gt;" APNS_SSL_PRIVATE_KEY_FILE = "&lt;your ssl private key.pem&gt;" class APNSClientContextFactory(ClientContextFactory): def __init__(self): self.ctx = SSL.Context(SSL.SSLv3_METHOD) self.ctx.use_certificate_file(APNS_SSL_CERTIFICATE_FILE) self.ctx.use_privatekey_file(APNS_SSL_PRIVATE_KEY_FILE) def getContext(self): return self.ctx class APNSProtocol(Protocol): def sendMessage(self, deviceToken, payload): # notification messages are binary messages in network order # using the following format: # &lt;1 byte command&gt; &lt;2 bytes length&gt;&lt;token&gt; &lt;2 bytes length&gt;&lt;payload&gt; fmt = "!cH32cH%dc" % len(payload) command = 0 msg = struct.pack(fmt, command, deviceToken, len(payload), payload) self.transport.write(msg) class APNSClientFactory(ClientFactory): def buildProtocol(self, addr): print "Connected to APNS Server %s:%u" % (addr.host, addr.port) return APNSProtocol() def clientConnectionLost(self, connector, reason): print "Lost connection. Reason: %s" % reason def clientConnectionFailed(self, connector, reason): print "Connection failed. Reason: %s" % reason if __name__ == '__main__': reactor.connectSSL(APNS_SERVER_HOSTNAME, APNS_SERVER_PORT, APNSClientFactory(), APNSClientContextFactory()) reactor.run() </code></pre>
 

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