initial code from XMPP2APNS