Struggling with this for days. I'm in over my head. I developed an iOS enterprise app that I want to add Push Notifications to. I think I have the client side (iPhone) set up all right, but the Windows app (VB) I am developing to connect to the APNs server is giving me a lot of trouble.
Here's the very basic code I am using that I found somewhere on the internet, with the exception line shown:
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
A google search brings up tons of different variations, but they are all apparently obsolete due to changes in the Push Notifications API over the years. I can't find anything that works, but this snippet at least gets me further than anything else has.
The exception:
I've tried a number of different variations on the .p12 file generated by the ID page on the Apple developer site, exported from the Mac's keychain, followed the steps from a number of different tutorials for converting to other formats (like .pem), or whatever, and nothing seems to work.
Interestingly, though, if I change the password string, the exception changes to The specified network password is not correct
, which makes me think that it is at least recognizing the password.
Can anyone lead me out of this mess?
Thanks!
我发现我忽略了将证书加载到开发服务器中的操作,在此处进行了介绍: https : //arashnorouzi.wordpress.com/2011/04/13/sending-apple-push-notifications-in-asp-net-% E2%80%93-部分-3- APNS-证书登记上窗口/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.