我正在开发一个带有mac的移动应用程序,但它连接到我正在linux上运行的测试服务器,并且我希望在此服务器上启用APN开发人员证书,问题是,是否可以在我的测试服务器上安装此证书,或者我将不得不在我的Linux机器上安装测试服务器?在java,linux开发机器的苹果推送通知服务
为了使这一点更清晰:
我的开发机器:一台Mac。 测试服务器:运行liferay的Linux机器6.0.6
我想在测试服务器上安装开发证书,以便测试推送通知。
非常感谢!
我正在开发一个带有mac的移动应用程序,但它连接到我正在linux上运行的测试服务器,并且我希望在此服务器上启用APN开发人员证书,问题是,是否可以在我的测试服务器上安装此证书,或者我将不得不在我的Linux机器上安装测试服务器?在java,linux开发机器的苹果推送通知服务
为了使这一点更清晰:
我的开发机器:一台Mac。 测试服务器:运行liferay的Linux机器6.0.6
我想在测试服务器上安装开发证书,以便测试推送通知。
非常感谢!
我想回答我的问题,因为它可能首先,在我需要生成的证书与如何获取设备令牌之间有一个可怕的混淆。
这是我所经历使这项工作的步骤:
这里是一个示例代码段,其中显示出证书的用武之地:
ApnsService service =
APNS.newService()
.withCert("/path/to/certificate.p12", "MyCertPassword")
.withSandboxDestination()
.build();
方法的第二个参数是为P12文件钥匙串访问让你设置的密码。
最后为了粘合东西,我使用了[UIApplication sharedApplication]
实例来注册接收推送通知,并通过在AppDelegate上实现一个方法,我得到了我需要的NSData格式的令牌,因此需要将其转换为十六进制字符串(在这个网站上有许多网站和问题的示例代码)。
就是这样,就是这个过程。
希望这有助于!
我对'liferay'一无所知,但这是他如何使用证书设置APN连接(在Rails服务器上)。请注意,您需要将证书转换为.pem文件(使用“OpenSSL的PKCS12 -in myfile.p12退房手续myfile.pem”):
@@apn_cert = nil
APN_SSL_KEY_FILE = 'lib/SSLCert_Private_Key.pem'
APN_SSL_HOST = 'gateway.sandbox.push.apple.com'
# APN_SSL_HOST = 'gateway.push.apple.com'
APN_SSL_PORT = 2195
APN_SSL_PASSWORD = '<password>'
def configure_apn_cert
puts "APN Service: Configuring APN cert"
@@apn_cert = File.read(File.join(RAILS_ROOT, APN_SSL_KEY_FILE))
@@apn_context = OpenSSL::SSL::SSLContext.new
@@apn_context.key = OpenSSL::PKey::RSA.new(@@apn_cert, APN_SSL_PASSWORD)
@@apn_context.cert = OpenSSL::X509::Certificate.new(@@apn_cert)
end
def create_and_configure_apn_server
configure_apn_cert if not @@apn_cert
puts "APN Service: Configuring APN SOCKET and SSL connection"
@apn_socket = TCPSocket.new(APN_SSL_HOST, APN_SSL_PORT)
@apn_ssl = OpenSSL::SSL::SSLSocket.new(@apn_socket, @@apn_context)
@apn_ssl.sync = true
@apn_ssl.connect
end
def close_apn_server
@apn_ssl.close
@apn_socket.close
end
def package_build_for_apn(token, content)
"\0\0 #{token}\0#{content.length.chr}#{content}"
end
def package_send_to_apn(package)
puts "APN Service: Sending #{package}"
bytes_written = @apn_ssl.write(package)
if bytes_written != package.length then
puts "APN Service: SSL write failed"
package_to_apn_show_write(bytes_written, package)
end
end
def apn_deliver_payload(token, payload)
# Convert the device string back into a byte string
tokenBinary = Base64.decode64(token)
# Transform the payload into an APN byte string
apn_content = payload.to_hash.to_json
apn_content_len = apn_content.length
# Build the apn_package per APN specification
apn_package = "\0\0 #{tokenBinary}\0#{apn_content_len.chr}#{apn_content}"
# Actually send it.
package_send_to_apn(apn_package)
end
def package_to_apn_show_write(bytes, package)
puts "Wrote: #{bytes_written}/ Tried: #{package.length}"
puts "Package: '#{package}'"
end
def package_to_apn_debug(token, content, package)
puts "Token(#{token.length}): #{token}"
puts "Content(#{content.length}): #{content}"
puts "Package(#{package.length}): #{package}"
end
我会尽量把它翻译成Java,我告诉你它是如何去的 – 2012-04-27 17:19:31
对于您的测试服务器开发,您使用的是什么语言? – GoZoner 2012-04-27 12:55:53
Java,实际上它是一个liferay应用程序,我在其中添加了Jersey – 2012-04-27 12:59:11
[您的问题不清楚]'测试服务器'是否已经在linux计算机上,您只是想为APN通知添加证书或者是服务器别的地方? – GoZoner 2012-04-27 14:02:43