diff --git a/client/client.pro b/client/client.pro
index a809362b..85c0580e 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -38,6 +38,7 @@ HEADERS += \
debug.h \
defines.h \
managementserver.h \
+ platforms/ios/MobileUtils.h \
platforms/linux/leakdetector.h \
protocols/protocols_defs.h \
settings.h \
@@ -95,6 +96,7 @@ SOURCES += \
debug.cpp \
main.cpp \
managementserver.cpp \
+ platforms/ios/MobileUtils.cpp \
platforms/linux/leakdetector.cpp \
protocols/protocols_defs.cpp \
settings.cpp \
@@ -300,10 +302,13 @@ ios {
platforms/ios/bigint.h \
platforms/ios/bigintipv6addr.h \
platforms/ios/ipaddress.h \
- platforms/ios/ipaddressrange.h
+ platforms/ios/ipaddressrange.h \
+ platforms/ios/QtAppDelegate.h \
+ platforms/ios/QtAppDelegate-C-Interface.h
SOURCES -= \
- platforms/ios/QRCodeReader.cpp
+ platforms/ios/QRCodeReader.cpp \
+ platforms/ios/MobileUtils.cpp
SOURCES += \
protocols/ios_vpnprotocol.mm \
@@ -313,6 +318,8 @@ ios {
platforms/ios/ipaddress.cpp \
platforms/ios/ipaddressrange.cpp \
platforms/ios/QRCodeReaderBase.mm
+ platforms/ios/QtAppDelegate.mm \
+ platforms/ios/MobileUtils.mm
Q_ENABLE_BITCODE.value = NO
Q_ENABLE_BITCODE.name = ENABLE_BITCODE
diff --git a/client/ios/app/Info.plist b/client/ios/app/Info.plist
index 38aec45e..20a28b2a 100644
--- a/client/ios/app/Info.plist
+++ b/client/ios/app/Info.plist
@@ -8,6 +8,19 @@
$(DEVELOPMENT_LANGUAGE)
CFBundleDisplayName
AmneziaVPN
+ CFBundleDocumentTypes
+
+
+ CFBundleTypeName
+ Amnezia VPN config
+ LSHandlerRank
+ Alternate
+ LSItemContentTypes
+
+ org.amnezia.AmneziaVPN.amnezia-config
+
+
+
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIcons
@@ -47,5 +60,31 @@
UIUserInterfaceStyle
Light
+ UTImportedTypeDeclarations
+
+
+ UTTypeConformsTo
+
+ public.data
+
+ UTTypeDescription
+ Amnezia VPN config
+ UTTypeIconFiles
+
+ UTTypeIdentifier
+ org.amnezia.AmneziaVPN.amnezia-config
+ UTTypeTagSpecification
+
+ public.filename-extension
+
+ vpn
+
+ public.mime-type
+
+ text/plain
+
+
+
+
diff --git a/client/main.cpp b/client/main.cpp
index 00f25743..1283e839 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -57,6 +57,10 @@
#include "native.h"
#endif
+#if defined(Q_OS_IOS)
+#include "QtAppDelegate-C-Interface.h"
+#endif
+
static void loadTranslator()
{
QTranslator* translator = new QTranslator;
@@ -88,7 +92,6 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#endif
-
#ifdef Q_OS_WIN
AllowSetForegroundWindow(0);
#endif
@@ -97,6 +100,10 @@ int main(int argc, char *argv[])
NativeHelpers::registerApplicationInstance(&app);
#endif
+#if defined(Q_OS_IOS)
+ QtAppDelegateInitialize();
+#endif
+
loadTranslator();
QFontDatabase::addApplicationFont(":/fonts/Lato-Black.ttf");
@@ -203,6 +210,10 @@ int main(int argc, char *argv[])
engine->rootContext()->setContextProperty("VpnLogic", uiLogic->vpnLogic());
engine->rootContext()->setContextProperty("WizardLogic", uiLogic->wizardLogic());
+#if defined(Q_OS_IOS)
+ setStartPageLogic(uiLogic->startPageLogic());
+#endif
+
engine->load(url);
QObject::connect(&app, &QCoreApplication::aboutToQuit, uiLogic, [&engine, uiLogic](){
diff --git a/client/platforms/ios/MobileUtils.cpp b/client/platforms/ios/MobileUtils.cpp
new file mode 100644
index 00000000..31b58c94
--- /dev/null
+++ b/client/platforms/ios/MobileUtils.cpp
@@ -0,0 +1,10 @@
+#include "MobileUtils.h"
+
+MobileUtils::MobileUtils()
+{
+
+}
+
+void MobileUtils::shareText(const QStringList& filesToSend) {
+
+}
diff --git a/client/platforms/ios/MobileUtils.h b/client/platforms/ios/MobileUtils.h
new file mode 100644
index 00000000..42aa4031
--- /dev/null
+++ b/client/platforms/ios/MobileUtils.h
@@ -0,0 +1,17 @@
+#ifndef MOBILEUTILS_H
+#define MOBILEUTILS_H
+
+#include
+#include
+
+class MobileUtils : public QObject {
+ Q_OBJECT
+
+public:
+ MobileUtils() = delete;
+
+public slots:
+ static void shareText(const QStringList& filesToSend);
+};
+
+#endif // MOBILEUTILS_H
diff --git a/client/platforms/ios/MobileUtils.mm b/client/platforms/ios/MobileUtils.mm
new file mode 100644
index 00000000..94c7c775
--- /dev/null
+++ b/client/platforms/ios/MobileUtils.mm
@@ -0,0 +1,33 @@
+#include "MobileUtils.h"
+
+#include
+
+static UIViewController* getViewController() {
+ NSArray *windows = [[UIApplication sharedApplication]windows];
+ for (UIWindow *window in windows) {
+ if (window.isKeyWindow) {
+ return window.rootViewController;
+ }
+ }
+ return nil;
+}
+
+void MobileUtils::shareText(const QStringList& filesToSend) {
+ NSMutableArray *sharingItems = [NSMutableArray new];
+
+ for (int i = 0; i < filesToSend.size(); i++) {
+ NSURL *logFileUrl = [[NSURL alloc] initFileURLWithPath:filesToSend[i].toNSString()];
+ [sharingItems addObject:logFileUrl];
+ }
+
+ UIViewController *qtController = getViewController();
+ if (!qtController) return;
+
+ UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
+
+ [qtController presentViewController:activityController animated:YES completion:nil];
+ UIPopoverPresentationController *popController = activityController.popoverPresentationController;
+ if (popController) {
+ popController.sourceView = qtController.view;
+ }
+}
diff --git a/client/platforms/ios/QtAppDelegate-C-Interface.h b/client/platforms/ios/QtAppDelegate-C-Interface.h
new file mode 100644
index 00000000..afd31e7d
--- /dev/null
+++ b/client/platforms/ios/QtAppDelegate-C-Interface.h
@@ -0,0 +1,9 @@
+#ifndef QTAPPDELEGATECINTERFACE_H
+#define QTAPPDELEGATECINTERFACE_H
+
+#include "ui/pages_logic/StartPageLogic.h"
+
+void QtAppDelegateInitialize();
+void setStartPageLogic(StartPageLogic*);
+
+#endif // QTAPPDELEGATECINTERFACE_H
diff --git a/client/platforms/ios/QtAppDelegate.h b/client/platforms/ios/QtAppDelegate.h
new file mode 100644
index 00000000..1e0dc412
--- /dev/null
+++ b/client/platforms/ios/QtAppDelegate.h
@@ -0,0 +1,9 @@
+#import
+#import "QtAppDelegate-C-Interface.h"
+
+#include "ui/pages_logic/StartPageLogic.h"
+
+@interface QtAppDelegate : UIResponder
++(QtAppDelegate *)sharedQtAppDelegate;
+@property (nonatomic) StartPageLogic* startPageLogic;
+@end
diff --git a/client/platforms/ios/QtAppDelegate.mm b/client/platforms/ios/QtAppDelegate.mm
new file mode 100644
index 00000000..f63bea35
--- /dev/null
+++ b/client/platforms/ios/QtAppDelegate.mm
@@ -0,0 +1,91 @@
+#import "QtAppDelegate.h"
+
+#include
+
+@implementation QtAppDelegate
+
++(QtAppDelegate *)sharedQtAppDelegate {
+ static dispatch_once_t pred;
+ static QtAppDelegate *shared = nil;
+ dispatch_once(&pred, ^{
+ shared = [[super alloc] init];
+ });
+ return shared;
+}
+
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ [application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
+ // Override point for customization after application launch.
+ NSLog(@"Did this launch option happen");
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application
+{
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application
+{
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+ NSLog(@"In the background");
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application
+{
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+ NSLog(@"In the foreground");
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application
+{
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application
+{
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
+ // We will add content here soon.
+ NSLog(@"In the completionHandler");
+}
+
+- (BOOL)application:(UIApplication *)app
+ openURL:(NSURL *)url
+ options:(NSDictionary *)options {
+
+ NSLog(@"Application openURL: %@", url);
+ if (url.fileURL) {
+ QString filePath(url.path.UTF8String);
+ qDebug() << "filePath:" << filePath;
+ if (filePath.isEmpty()) return NO;
+
+ QFile file(filePath);
+ bool isOpenFile = file.open(QIODevice::ReadOnly);
+ qDebug() << "isOpenFile:" << isOpenFile;
+ QByteArray data = file.readAll();
+
+ [QtAppDelegate sharedQtAppDelegate].startPageLogic->importConnectionFromCode(QString(data));
+ return YES;
+ }
+ return NO;
+}
+
+
+void QtAppDelegateInitialize()
+{
+ [[UIApplication sharedApplication] setDelegate: [QtAppDelegate sharedQtAppDelegate]];
+ NSLog(@"Created a new AppDelegate");
+}
+
+void setStartPageLogic(StartPageLogic* startPage) {
+ [QtAppDelegate sharedQtAppDelegate].startPageLogic = startPage;
+}
+
+@end
diff --git a/client/scripts/xcode_patcher.rb b/client/scripts/xcode_patcher.rb
index 983ec0c7..0a0550ca 100644
--- a/client/scripts/xcode_patcher.rb
+++ b/client/scripts/xcode_patcher.rb
@@ -271,7 +271,11 @@ class XCodeprojPatcher
@target_extension.build_configurations.each do |config|
config.base_configuration_reference = @configFile
- config.build_settings['LD_RUNPATH_SEARCH_PATHS'] ||= '"$(inherited) @executable_path/../Frameworks @executable_path/../../Frameworks"'
+ config.build_settings['LD_RUNPATH_SEARCH_PATHS'] ||= [
+ '$(inherited)',
+ '@executable_path/../Frameworks',
+ '@executable_path/../../Frameworks'
+ ]
config.build_settings['SWIFT_VERSION'] ||= '5.0'
config.build_settings['CLANG_ENABLE_MODULES'] ||= 'YES'
config.build_settings['SWIFT_OBJC_BRIDGING_HEADER'] ||= 'macos/networkextension/WireGuardNetworkExtension-Bridging-Header.h'
diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp
index 878facb7..fe2d541d 100644
--- a/client/ui/uilogic.cpp
+++ b/client/ui/uilogic.cpp
@@ -48,6 +48,8 @@
#include "platforms/android/android_controller.h"
#endif
+#include "platforms/ios/MobileUtils.h"
+
#include "pages_logic/AppSettingsLogic.h"
#include "pages_logic/GeneralSettingsLogic.h"
#include "pages_logic/NetworkSettingsLogic.h"
@@ -612,21 +614,10 @@ PageEnumNS::Page UiLogic::currentPage()
void UiLogic::saveTextFile(const QString& desc, const QString& suggestedName, QString ext, const QString& data)
{
-// ext.replace("*", "");
-// QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
-// QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*" + ext);
-
-// if (fileName.isEmpty()) return;
-// if (!fileName.endsWith(ext)) fileName.append(ext);
-
-// QFile save(fileName);
-// save.open(QIODevice::WriteOnly);
-// save.write(data.toUtf8());
-// save.close();
-
-// QFileInfo fi(fileName);
-// QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
-
+#ifdef Q_OS_IOS
+ shareTempFile(suggestedName, ext, data);
+ return;
+#endif
ext.replace("*", "");
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
@@ -681,3 +672,23 @@ void UiLogic::copyToClipboard(const QString &text)
{
qApp->clipboard()->setText(text);
}
+
+void UiLogic::shareTempFile(const QString &suggestedName, QString ext, const QString& data) {
+ ext.replace("*", "");
+ QString fileName = QDir::tempPath() + "/" + suggestedName;
+
+ if (fileName.isEmpty()) return;
+ if (!fileName.endsWith(ext)) fileName.append(ext);
+
+ QFile::remove(fileName);
+ qDebug() << "UiLogic::shareTempFile" << fileName;
+
+ QFile save(fileName);
+ save.open(QIODevice::WriteOnly);
+ save.write(data.toUtf8());
+ save.close();
+
+ QStringList filesToSend;
+ filesToSend.append(fileName);
+ MobileUtils::shareText(filesToSend);
+}
diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h
index ff7d7406..4e818bcc 100644
--- a/client/ui/uilogic.h
+++ b/client/ui/uilogic.h
@@ -104,6 +104,8 @@ public:
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
Q_INVOKABLE void copyToClipboard(const QString& text);
+ void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
+
QString getDialogConnectErrorText() const;
void setDialogConnectErrorText(const QString &dialogConnectErrorText);