NSURLSession fake call to exec iOS network settings dialog

This commit is contained in:
pokamest
2024-05-03 17:00:19 -07:00
parent 6f31943cac
commit 62c33e373e
6 changed files with 38 additions and 0 deletions

View File

@@ -82,6 +82,10 @@ void ApiController::updateServerConfigFromApi(const QString &installationUuid, c
QString endpoint = serverConfig.value(configKey::apiEdnpoint).toString();
request.setUrl(endpoint);
#ifdef Q_OS_IOS
m_mobileUtils.fetchUrl(endpoint);
#endif
QString protocol = serverConfig.value(configKey::protocol).toString();
ApiPayloadData apiPayloadData = generateApiPayloadData(protocol);

View File

@@ -5,6 +5,10 @@
#include "configurators/openvpn_configurator.h"
#ifdef Q_OS_IOS
#include "platforms/ios/MobileUtils.h"
#endif
class ConnectionController;
class ApiController : public QObject
@@ -20,6 +24,7 @@ public slots:
private:
ConnectionController *m_connectionController;
MobileUtils m_mobileUtils;
struct ApiPayloadData {
OpenVpnConfigurator::ConnectionData certRequest;

View File

@@ -51,6 +51,13 @@
<true/>
<key>NSCameraUsageDescription</key>
<string>Amnezia VPN needs access to the camera for reading QR-codes.</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>

View File

@@ -64,6 +64,7 @@ int main(int argc, char *argv[])
qInfo().noquote() << QString("Started %1 version %2 %3").arg(APPLICATION_NAME, APP_VERSION, GIT_COMMIT_HASH);
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName(), QSysInfo::currentCpuArchitecture());
qInfo().noquote() << QString("SSL backend: %1").arg(QSslSocket::sslLibraryVersionString());
return app.exec();
}

View File

@@ -2,6 +2,9 @@
#define MOBILEUTILS_H
#include <QObject>
#include <QDebug>
#include <QEventLoop>
#include <QString>
#include <QStringList>
class MobileUtils : public QObject
@@ -14,6 +17,7 @@ public:
public slots:
bool shareText(const QStringList &filesToSend);
QString openFile();
void fetchUrl(const QString &urlString);
signals:
void finished();

View File

@@ -3,7 +3,9 @@
#include <UIKit/UIKit.h>
#include <Security/Security.h>
#include <QDebug>
#include <QEventLoop>
#include <QString>
static UIViewController* getViewController() {
NSArray *windows = [[UIApplication sharedApplication]windows];
@@ -107,3 +109,18 @@ QString MobileUtils::openFile() {
return filePath;
}
void MobileUtils::fetchUrl(const QString &urlString) {
NSURL *url = [NSURL URLWithString:urlString.toNSString()];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
qDebug() << "MobileUtils::fetchUrl error:" << error.localizedDescription;
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
QString responseBody = QString::fromUtf8((const char*)data.bytes, data.length);
qDebug() << "MobileUtils::fetchUrl server response:" << httpResponse.statusCode << "\n\n" <<responseBody;
}
}];
[task resume];
}