i tried it some ours now but i could not get it to work. I want to push some notifications from a Qt Application. Tried to get it to work on macOS Sierra with Qt 5.8 installation and on Pi3 also with Qt 5.8.
I created my push certificate with "fastlane pem" and i tested it with "Pusher" and it works correct. But i cannot get it to work in Qt....
At first is the code i use to initialize and connect the QSslSocket:
QSslSocket * ssl = new QSslSocket;
connect(ssl, &QSslSocket::encrypted, this, &IOSPusher::encrypted );
connect(ssl, static_cast<void(QSslSocket::*)(const QList<QSslError> &)>(&QSslSocket::sslErrors),this,&IOSPusher::sslErrors);
connect(ssl, static_cast<void(QSslSocket::*)(QAbstractSocket::SocketError)>(&QSslSocket::error),this, &IOSPusher::error );
connect(ssl,&QSslSocket::stateChanged,this,&IOSPusher::stateChanged );
Loading the certificate
QString path = QStandardPaths::writableLocation(certificateLocation) + "/apns.pem";
const auto certs = QSslCertificate::fromPath(path);
if(certs.count() > 0){
qDebug() << "IOSPusher: Certificate loaded successfully";
}else{
qDebug() << "Could not load certificate : " + path;
}
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setCaCertificates(certs);
ssl->setSslConfiguration(config);
ssl->connectToHostEncrypted( gateway.sandbox.push.apple.com,2195 );
And thats the output i get:
IOSPusher: Certificate loaded successfully
IOSPusher::stateChanged QAbstractSocket::HostLookupState
IOSPusher::stateChanged QAbstractSocket::ConnectingState
IOSPusher::stateChanged QAbstractSocket::ConnectedState
IOSPusher::error QAbstractSocket::SocketError(13)
IOSPusher::stateChanged QAbstractSocket::ClosingState
IOSPusher::stateChanged QAbstractSocket::UnconnectedState
So according to the Qt documentation the error:
QAbstractSocket::SocketError(13)
means the following:
SslHandshakeFailedError
And
> the SSL/TLS handshake failed and the encrypted channel could not be established. The sslErrors() signal should have been emitted.
But the sslErrors()
signal will not be emitted in my case....
The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)
Any ideas or samples how i can establish a encrypted connection to apple?
Thanks in advance!