share file for iOS

This commit is contained in:
eugenyorbitsoftcom 2022-07-13 16:08:55 +06:00
parent 9ed16b81e8
commit 9601506270
6 changed files with 94 additions and 17 deletions

View file

@ -0,0 +1,10 @@
#include "MobileUtils.h"
MobileUtils::MobileUtils()
{
}
void MobileUtils::shareText(const QStringList& filesToSend) {
}

View file

@ -0,0 +1,17 @@
#ifndef MOBILEUTILS_H
#define MOBILEUTILS_H
#include <QObject>
#include <QStringList>
class MobileUtils : public QObject {
Q_OBJECT
public:
MobileUtils() = delete;
public slots:
static void shareText(const QStringList& filesToSend);
};
#endif // MOBILEUTILS_H

View file

@ -0,0 +1,33 @@
#include "MobileUtils.h"
#include <UIKit/UIKit.h>
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;
}
}