需要帮助从 Windows vs2017 程序访问 Apple APN 服务器
Need help accessing Apple APN server from a Windows vs2017 program
为此苦苦挣扎了好几天。我在我的头上。我开发了一个 iOS 企业应用程序,我想在其中添加推送通知。我认为我的客户端 (iPhone) 设置正常,但是我正在开发连接到 APNs 服务器的 Windows 应用程序 (VB) 给我带来了很多麻烦.
这是我在互联网上找到的最基本的代码,其中显示了异常行:
Using client As New TcpClient()
client.Connect("gateway.sandbox.push.apple.com", 2195)
Using networkStream As NetworkStream = client.GetStream()
txtErrorMessages.AppendText("Client connected." & vbNewLine)
Dim clientCertificate As New X509Certificate(FileSystem.CurrentDirectory & "/apns-dev-key.p12", "abc123")
Dim clientCertificateCollection As New X509CertificateCollection(New X509Certificate(0) {clientCertificate})
' Create an SSL stream that will close the client's stream.
Dim sslStream As New SslStream(client.GetStream(), False, AddressOf ValidateServerCertificate, Nothing)
Try
[exception thrown here] sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, False)
Catch ex As AuthenticationException
txtErrorMessages.AppendText(String.Format("Exception: {0}", ex.Message) & vbNewLine)
If ex.InnerException IsNot Nothing Then
txtErrorMessages.AppendText(String.Format("Inner exception: {0}", ex.InnerException.Message) & vbNewLine)
End If
txtErrorMessages.AppendText(String.Format("Authentication failed - closing the connection.") & vbnewline)
client.Close()
Return
End Try
End Using
End Using
google 搜索会带来大量不同的变体,但由于多年来推送通知 API 的变化,它们显然都已过时。我找不到任何有用的东西,但这段代码至少比其他任何东西都让我走得更远。
异常:
我在 Apple 开发者网站上的 ID 页面生成的 .p12 文件上尝试了多种不同的变体,从 Mac 的钥匙串中导出,遵循了许多不同的步骤转换为其他格式(如 .pem)或其他格式的教程,但似乎没有任何效果。
有趣的是,如果我更改密码字符串,异常会变为 The specified network password is not correct
,这让我认为它至少可以识别密码。
谁能带我走出困境?
谢谢!
为此苦苦挣扎了好几天。我在我的头上。我开发了一个 iOS 企业应用程序,我想在其中添加推送通知。我认为我的客户端 (iPhone) 设置正常,但是我正在开发连接到 APNs 服务器的 Windows 应用程序 (VB) 给我带来了很多麻烦.
这是我在互联网上找到的最基本的代码,其中显示了异常行:
Using client As New TcpClient()
client.Connect("gateway.sandbox.push.apple.com", 2195)
Using networkStream As NetworkStream = client.GetStream()
txtErrorMessages.AppendText("Client connected." & vbNewLine)
Dim clientCertificate As New X509Certificate(FileSystem.CurrentDirectory & "/apns-dev-key.p12", "abc123")
Dim clientCertificateCollection As New X509CertificateCollection(New X509Certificate(0) {clientCertificate})
' Create an SSL stream that will close the client's stream.
Dim sslStream As New SslStream(client.GetStream(), False, AddressOf ValidateServerCertificate, Nothing)
Try
[exception thrown here] sslStream.AuthenticateAsClient("gateway.sandbox.push.apple.com", clientCertificateCollection, SslProtocols.Default, False)
Catch ex As AuthenticationException
txtErrorMessages.AppendText(String.Format("Exception: {0}", ex.Message) & vbNewLine)
If ex.InnerException IsNot Nothing Then
txtErrorMessages.AppendText(String.Format("Inner exception: {0}", ex.InnerException.Message) & vbNewLine)
End If
txtErrorMessages.AppendText(String.Format("Authentication failed - closing the connection.") & vbnewline)
client.Close()
Return
End Try
End Using
End Using
google 搜索会带来大量不同的变体,但由于多年来推送通知 API 的变化,它们显然都已过时。我找不到任何有用的东西,但这段代码至少比其他任何东西都让我走得更远。
异常:
我在 Apple 开发者网站上的 ID 页面生成的 .p12 文件上尝试了多种不同的变体,从 Mac 的钥匙串中导出,遵循了许多不同的步骤转换为其他格式(如 .pem)或其他格式的教程,但似乎没有任何效果。
有趣的是,如果我更改密码字符串,异常会变为 The specified network password is not correct
,这让我认为它至少可以识别密码。
谁能带我走出困境?
谢谢!