From 38ad92207e80c0ad441ae531c79cd3e14305ad70 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 25 Jun 2021 23:22:28 +0200 Subject: [PATCH] Implement sharing on IOS --- README.md | 8 +- blueROCK.pro | 49 +++++- headers/bluerockbackend.h | 4 +- headers/iospermissionutils.h | 22 +++ headers/shareUtils/androidshareutils.h | 2 +- headers/shareUtils/ios/docviewcontroller.h | 21 +++ headers/shareUtils/ios/iosshareutils.h | 31 ++++ headers/shareUtils/platformshareutils.h | 2 +- headers/shareUtils/shareutils.h | 2 +- ios/Info.plist | 45 +++++ ios/blueROCK.entitlements | 11 ++ .../qml/Components/SpeedFlowChartPopup.qml | 4 +- sources/bluerockbackend.cpp | 8 +- sources/iospermissionutils.mm | 34 ++++ sources/main.cpp | 1 - sources/shareUtils/androidshareutils.cpp | 4 +- sources/shareUtils/ios/docviewcontroller.mm | 32 ++++ sources/shareUtils/ios/iosshareutils.mm | 156 ++++++++++++++++++ sources/shareUtils/platformshareutils.cpp | 4 +- sources/shareUtils/shareutils.cpp | 6 +- 20 files changed, 425 insertions(+), 21 deletions(-) create mode 100644 headers/iospermissionutils.h create mode 100644 headers/shareUtils/ios/docviewcontroller.h create mode 100755 headers/shareUtils/ios/iosshareutils.h create mode 100644 ios/Info.plist create mode 100644 ios/blueROCK.entitlements create mode 100644 sources/iospermissionutils.mm create mode 100644 sources/shareUtils/ios/docviewcontroller.mm create mode 100755 sources/shareUtils/ios/iosshareutils.mm diff --git a/README.md b/README.md index 4aa83b8..80f01de 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Digital Rock ranking -App to view ranking and calendar data from https://www.digitalrock.de/ \ No newline at end of file +App to view ranking and calendar data from https://www.digitalrock.de/ + +# Init +´´´ +git submodule init +git submodule update +´´´ diff --git a/blueROCK.pro b/blueROCK.pro index d830ff9..2ad3af7 100644 --- a/blueROCK.pro +++ b/blueROCK.pro @@ -1,4 +1,4 @@ -QT += quick qml quickcontrols2 purchasing printsupport +QT += quick qml quickcontrols2 purchasing CONFIG += c++11 VERSION = 0.5.0 @@ -15,7 +15,7 @@ DEFINES += QT_DEPRECATED_WARNINGS # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -INCLUDEPATH *= $$PWD/headers +INCLUDEPATH += $$PWD/headers # Add version to define DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\" @@ -35,8 +35,6 @@ HEADERS += \ RESOURCES += resources/qml/qml.qrc \ resources/shared/shared.qrc \ - #resources/shared/icons/bluerock/index.theme \ - \ #$$files(resources/shared/icons/*.png, true) resources/translations/translations.qrc TRANSLATIONS += resources/translations/en.ts \ @@ -54,7 +52,8 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += \ - CHANGELOG.md + CHANGELOG.md \ + README.md android { QT += androidextras @@ -97,14 +96,54 @@ android { } ios { + OBJECTIVE_SOURCES += sources/shareUtils/ios/iosshareutils.mm \ + sources/iospermissionutils.mm \ + sources/shareUtils/ios/docviewcontroller.mm + + HEADERS += headers/shareUtils/ios/iosshareutils.h \ + headers/iospermissionutils.h \ + headers/shareUtils/ios/docviewcontroller.h + + OTHER_FILES += ios/Info.plist \ + ios/blueROCK.entitlements + + QMAKE_INFO_PLIST = ios/Info.plist + + + #QMAKE_IOS_DEPLOYMENT_TARGET = 12.0 + + #disable_warning.name = GCC_WARN_64_TO_32_BIT_CONVERSION + #disable_warning.value = NO + #QMAKE_MAC_XCODE_SETTINGS += disable_warning + + # see https://bugreports.qt.io/browse/QTCREATORBUG-16968 + # ios_signature.pri not part of project repo because of private signature details + # contains: + # QMAKE_XCODE_CODE_SIGN_IDENTITY = "iPhone Developer" + # MY_DEVELOPMENT_TEAM.name = DEVELOPMENT_TEAM + # MY_DEVELOPMENT_TEAM.value = your team Id from Apple Developer Account + # QMAKE_MAC_XCODE_SETTINGS += MY_DEVELOPMENT_TEAM + + #include(ios_signature.pri) + QMAKE_ASSET_CATALOGS += resources/shared/Assets.xcassets + + MY_ENTITLEMENTS.name = CODE_SIGN_ENTITLEMENTS + MY_ENTITLEMENTS.value = $$PWD/ios/blueROCK.entitlements + QMAKE_MAC_XCODE_SETTINGS += MY_ENTITLEMENTS + + MY_BUNDLE_ID.name = PRODUCT_BUNDLE_IDENTIFIER + MY_BUNDLE_ID.value = de.itsblue.bluerock + QMAKE_MAC_XCODE_SETTINGS += MY_BUNDLE_ID xcode_product_bundle_identifier_setting.value = "de.itsblue.bluerock" + PRODUCT_IDENTIFIER = de.itsblue.bluerock } CONFIG += enable_decoder_qr_code \ enable_encoder_qr_code \ qzxing_multimedia \ qzxing_qml + include(qzxing/src/QZXing-components.pri) # this has to be the last line! diff --git a/headers/bluerockbackend.h b/headers/bluerockbackend.h index ffbef21..6308a64 100644 --- a/headers/bluerockbackend.h +++ b/headers/bluerockbackend.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ #ifdef Q_OS_ANDROID #include +#elif defined Q_OS_IOS +#include "iospermissionutils.h" #endif #include "shareUtils/shareutils.h" @@ -51,6 +52,7 @@ private: QVariantMap _senddata(QUrl serviceUrl, QUrlQuery pdata = QUrlQuery()); ShareUtils* _shareUtils; + IosPermissionUtils* _iosPermissionUtils; const QStringList _validBaseDomains = {"digitalrock.de", "bluerock.dev"}; bool _pendingIntentsChecked; signals: diff --git a/headers/iospermissionutils.h b/headers/iospermissionutils.h new file mode 100644 index 0000000..132e60f --- /dev/null +++ b/headers/iospermissionutils.h @@ -0,0 +1,22 @@ +#ifndef IOSPERMISSIONUTILS_H +#define IOSPERMISSIONUTILS_H + +#include +#include + +class IosPermissionUtils : QObject +{ + Q_OBJECT +public: + IosPermissionUtils(); + bool isCameraPermissionGranted(); + bool requestCameraPermission(); + +private: + QEventLoop* _responseWaitLoop; + +signals: + void permissionRequestFinished(bool result); +}; + +#endif // IOSPERMISSIONUTILS_H diff --git a/headers/shareUtils/androidshareutils.h b/headers/shareUtils/androidshareutils.h index b74fd86..cbb30b0 100755 --- a/headers/shareUtils/androidshareutils.h +++ b/headers/shareUtils/androidshareutils.h @@ -18,7 +18,7 @@ public: bool checkMimeTypeView(const QString &mimeType) override; bool checkMimeTypeEdit(const QString &mimeType) override; virtual QString getTemporaryFileLocationPath() override; - void shareText(const QString &text) override; + void shareText(const QString &text, const QUrl &url) override; void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; void editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; diff --git a/headers/shareUtils/ios/docviewcontroller.h b/headers/shareUtils/ios/docviewcontroller.h new file mode 100644 index 0000000..b70867b --- /dev/null +++ b/headers/shareUtils/ios/docviewcontroller.h @@ -0,0 +1,21 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#ifndef DOCVIEWCONTROLLER_HPP +#define DOCVIEWCONTROLLER_HPP + +#import +#import "iosshareutils.h" + +@interface DocViewController : UIViewController + +@property int requestId; + +@property IosShareUtils *mIosShareUtils; + +@end + + + +#endif // DOCVIEWCONTROLLER_HPP diff --git a/headers/shareUtils/ios/iosshareutils.h b/headers/shareUtils/ios/iosshareutils.h new file mode 100755 index 0000000..55d7bf7 --- /dev/null +++ b/headers/shareUtils/ios/iosshareutils.h @@ -0,0 +1,31 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#ifndef __IOSSHAREUTILS_H__ +#define __IOSSHAREUTILS_H__ + +#include "headers/shareUtils/platformshareutils.h" + +class IosShareUtils : public PlatformShareUtils +{ + Q_OBJECT + +public: + explicit IosShareUtils(QObject *parent = 0); + bool checkMimeTypeView(const QString &mimeType) override; + bool checkMimeTypeEdit(const QString &mimeType) override; + void shareText(const QString &text, const QUrl &url) override; + void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; + void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; + void editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) override; + + void handleDocumentPreviewDone(const int &requestId); + +public slots: + void handleFileUrlReceived(const QUrl &url); + void handleHttpsUrlReceived(const QUrl &url); + +}; + +#endif diff --git a/headers/shareUtils/platformshareutils.h b/headers/shareUtils/platformshareutils.h index 310917d..99781e1 100644 --- a/headers/shareUtils/platformshareutils.h +++ b/headers/shareUtils/platformshareutils.h @@ -40,7 +40,7 @@ public: virtual bool checkMimeTypeView(const QString &mimeType); virtual bool checkMimeTypeEdit(const QString &mimeType); virtual QString getTemporaryFileLocationPath(); - virtual void shareText(const QString &text); + virtual void shareText(const QString &text, const QUrl &url); virtual void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); virtual void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); virtual void editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); diff --git a/headers/shareUtils/shareutils.h b/headers/shareUtils/shareutils.h index 6eb61df..750ce73 100755 --- a/headers/shareUtils/shareutils.h +++ b/headers/shareUtils/shareutils.h @@ -49,7 +49,7 @@ public: Q_INVOKABLE bool checkMimeTypeView(const QString &mimeType); Q_INVOKABLE bool checkMimeTypeEdit(const QString &mimeType); Q_INVOKABLE QString getTemporaryFileLocationPath(); - Q_INVOKABLE void shareText(const QString &text); + Q_INVOKABLE void shareText(const QString &text, const QUrl &url); Q_INVOKABLE void sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); Q_INVOKABLE void viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); Q_INVOKABLE void editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId); diff --git a/ios/Info.plist b/ios/Info.plist new file mode 100644 index 0000000..b38762e --- /dev/null +++ b/ios/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDisplayName + ${PRODUCT_NAME} + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + ${ASSETCATALOG_COMPILER_APPICON_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + ${QMAKE_SHORT_VERSION} + CFBundleSignature + ${QMAKE_PKGINFO_TYPEINFO} + CFBundleVersion + ${QMAKE_FULL_VERSION} + LSApplicationQueriesSchemes + + https + + LSRequiresIPhoneOS + + MinimumOSVersion + ${IPHONEOS_DEPLOYMENT_TARGET} + NOTE + This file was generated by Qt/QMake. + NSCameraUsageDescription + blueROCK would like to access the camera. + UILaunchStoryboardName + LaunchScreen + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ios/blueROCK.entitlements b/ios/blueROCK.entitlements new file mode 100644 index 0000000..9981ec4 --- /dev/null +++ b/ios/blueROCK.entitlements @@ -0,0 +1,11 @@ + + + + + com.apple.developer.associated-domains + + applinks:l.bluerock.dev + applinks:app.bluerock.dev + + + diff --git a/resources/qml/Components/SpeedFlowChartPopup.qml b/resources/qml/Components/SpeedFlowChartPopup.qml index 85d0d47..5456a8d 100644 --- a/resources/qml/Components/SpeedFlowChartPopup.qml +++ b/resources/qml/Components/SpeedFlowChartPopup.qml @@ -8,8 +8,8 @@ Rectangle { property var flowchartData: ({}) // always unlock in debug mode - property bool unlocked: QT_DEBUG || appSettings.read("speedBackendPurchase") === "1" - //property bool unlocked: appSettings.read("speedBackendPurchase") === "1" + //property bool unlocked: QT_DEBUG || appSettings.read("speedBackendPurchase") === "1" + property bool unlocked: appSettings.read("speedBackendPurchase") === "1" state: "hidden" diff --git a/sources/bluerockbackend.cpp b/sources/bluerockbackend.cpp index 9ebbd46..38094d5 100644 --- a/sources/bluerockbackend.cpp +++ b/sources/bluerockbackend.cpp @@ -25,6 +25,8 @@ BlueRockBackend::BlueRockBackend(QObject *parent) : QObject(parent), _pendingInt #if defined(Q_OS_ANDROID) connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(onApplicationStateChanged(Qt::ApplicationState))); +#elif defined Q_OS_IOS + this->_iosPermissionUtils = new IosPermissionUtils(); #endif } @@ -96,7 +98,7 @@ QVariantMap BlueRockBackend::getParamsFromUrl(QString stringUrl) { void BlueRockBackend::shareResultsAsUrl(QString url, QString compName) { //% "Check out the results of %1 over here:" - this->_shareUtils->shareText(qtTrId("#shareResultsLinkText").arg(compName) + "\n" + url); + this->_shareUtils->shareText(qtTrId("#shareResultsLinkText").arg(compName) + " \n", url); } void BlueRockBackend::shareResultsAsPoster(QString url, QString compName) { @@ -146,6 +148,8 @@ bool BlueRockBackend::isCameraPermissionGranted() { #ifdef Q_OS_ANDROID QtAndroid::PermissionResult cameraAccess = QtAndroid::checkPermission("android.permission.CAMERA"); return cameraAccess == QtAndroid::PermissionResult::Granted; +#elif defined Q_OS_IOS + return this->_iosPermissionUtils->isCameraPermissionGranted(); #else return true; #endif @@ -203,6 +207,8 @@ bool BlueRockBackend::requestCameraPermission() { } return true; +#elif defined Q_OS_IOS + return this->_iosPermissionUtils->requestCameraPermission(); #else return true; #endif diff --git a/sources/iospermissionutils.mm b/sources/iospermissionutils.mm new file mode 100644 index 0000000..7935404 --- /dev/null +++ b/sources/iospermissionutils.mm @@ -0,0 +1,34 @@ +#import "../headers/iospermissionutils.h" +#import +#import + +IosPermissionUtils::IosPermissionUtils() : QObject(nullptr) +{ + this->_responseWaitLoop = new QEventLoop(this); +} + +bool IosPermissionUtils::isCameraPermissionGranted() { + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; + return status == AVAuthorizationStatusAuthorized; +} + +bool IosPermissionUtils::requestCameraPermission() { + if(this->isCameraPermissionGranted()) + return true; + + if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) { + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { + // Will get here on both iOS 7 & 8 even though camera permissions weren't required + // until iOS 8. So for iOS 7 permission will always be granted. + this->_responseWaitLoop->exit(granted); + }]; + } + + if(!this->_responseWaitLoop->exec()) { + // permission was not granted -> open settings + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; + return false; + } + + return true; +} diff --git a/sources/main.cpp b/sources/main.cpp index 91f6832..4f35905 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "QZXing.h" diff --git a/sources/shareUtils/androidshareutils.cpp b/sources/shareUtils/androidshareutils.cpp index d6a98b8..42b9b8f 100755 --- a/sources/shareUtils/androidshareutils.cpp +++ b/sources/shareUtils/androidshareutils.cpp @@ -58,9 +58,9 @@ QString AndroidShareUtils::getTemporaryFileLocationPath() { return QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0) + "/temporaryFiles"; } -void AndroidShareUtils::shareText(const QString &text) +void AndroidShareUtils::shareText(const QString &text, const QUrl &url) { - QAndroidJniObject jsText = QAndroidJniObject::fromString(text); + QAndroidJniObject jsText = QAndroidJniObject::fromString(text + url.toString()); jboolean ok = QAndroidJniObject::callStaticMethod("org/ekkescorner/utils/QShareUtils", "shareText", "(Ljava/lang/String;)Z", diff --git a/sources/shareUtils/ios/docviewcontroller.mm b/sources/shareUtils/ios/docviewcontroller.mm new file mode 100644 index 0000000..c4a5e36 --- /dev/null +++ b/sources/shareUtils/ios/docviewcontroller.mm @@ -0,0 +1,32 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#import "headers/shareUtils/ios/docviewcontroller.h" + +#include + +@interface DocViewController () +@end +@implementation DocViewController +#pragma mark - +#pragma mark View Life Cycle +- (void)viewDidLoad { + [super viewDidLoad]; +} +#pragma mark - +#pragma mark Document Interaction Controller Delegate Methods +- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller { +#pragma unused (controller) + return self; +} +- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller +{ +#pragma unused (controller) + qDebug() << "end preview"; + + self.mIosShareUtils->handleDocumentPreviewDone(self.requestId); + + [self removeFromParentViewController]; +} +@end diff --git a/sources/shareUtils/ios/iosshareutils.mm b/sources/shareUtils/ios/iosshareutils.mm new file mode 100755 index 0000000..a8bc5b6 --- /dev/null +++ b/sources/shareUtils/ios/iosshareutils.mm @@ -0,0 +1,156 @@ +// (c) 2017 Ekkehard Gentz (ekke) @ekkescorner +// my blog about Qt for mobile: http://j.mp/qt-x +// see also /COPYRIGHT and /LICENSE + +#import "headers/shareUtils/ios/iosshareutils.h" + +#import +#import +#import +#import +#import +#import + +#import + +#import "headers/shareUtils/ios/docviewcontroller.h" + +IosShareUtils::IosShareUtils(QObject *parent) : PlatformShareUtils(parent) +{ + // Sharing Files from other iOS Apps I got the ideas and some code contribution from: + // Thomas K. Fischer (@taskfabric) - http://taskfabric.com - thx + QDesktopServices::setUrlHandler("file", this, "handleFileUrlReceived"); + QDesktopServices::setUrlHandler("https", this, "handleHttpsUrlReceived"); +} + +bool IosShareUtils::checkMimeTypeView(const QString &mimeType) { +#pragma unused (mimeType) + // dummi implementation on iOS + // MimeType not used yet + return true; +} + +bool IosShareUtils::checkMimeTypeEdit(const QString &mimeType) { +#pragma unused (mimeType) + // dummi implementation on iOS + // MimeType not used yet + return true; +} + +void IosShareUtils::shareText(const QString &text, const QUrl &url) { + + NSMutableArray *sharingItems = [NSMutableArray new]; + + if (!text.isEmpty()) { + [sharingItems addObject:text.toNSString()]; + } + + if (url.isValid()) { + [sharingItems addObject:url.toNSURL()]; + } + + // get the main window rootViewController + UIViewController *qtUIViewController = [[UIApplication sharedApplication].keyWindow rootViewController]; + + UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; + if ( [activityController respondsToSelector:@selector(popoverPresentationController)] ) { // iOS8 + activityController.popoverPresentationController.sourceView = qtUIViewController.view; + } + [qtUIViewController presentViewController:activityController animated:YES completion:nil]; +} + +// altImpl not used yet on iOS, on Android twi ways to use JNI +void IosShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { +#pragma unused (title, mimeType) + + NSString* nsFilePath = filePath.toNSString(); + NSURL *nsFileUrl = [NSURL fileURLWithPath:nsFilePath]; + + static DocViewController* docViewController = nil; + if(docViewController!=nil) + { + [docViewController removeFromParentViewController]; + [docViewController release]; + } + + UIDocumentInteractionController* documentInteractionController = nil; + documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:nsFileUrl]; + + UIViewController* qtUIViewController = [[[[UIApplication sharedApplication]windows] firstObject]rootViewController]; + if(qtUIViewController!=nil) + { + docViewController = [[DocViewController alloc] init]; + + docViewController.requestId = requestId; + // we need this to be able to execute handleDocumentPreviewDone() method, + // when preview was finished + docViewController.mIosShareUtils = this; + + [qtUIViewController addChildViewController:docViewController]; + documentInteractionController.delegate = docViewController; + // [documentInteractionController presentPreviewAnimated:YES]; + if(![documentInteractionController presentPreviewAnimated:YES]) + { + emit shareError(0, tr("No App found to open: %1").arg(filePath)); + } + } +} + + +void IosShareUtils::viewFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { +#pragma unused (title, mimeType) + + sendFile(filePath, title, mimeType, requestId); +} + +void IosShareUtils::editFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { +#pragma unused (title, mimeType) + + sendFile(filePath, title, mimeType, requestId); +} + +void IosShareUtils::handleDocumentPreviewDone(const int &requestId) +{ + // documentInteractionControllerDidEndPreview + qDebug() << "handleShareDone: " << requestId; + emit shareFinished(requestId); +} + +void IosShareUtils::handleFileUrlReceived(const QUrl &url) +{ + QString incomingUrl = url.toString(); + if(incomingUrl.isEmpty()) { + qWarning() << "setFileUrlReceived: we got an empty URL"; + emit shareError(0, tr("Empty URL received")); + return; + } + qDebug() << "IosShareUtils setFileUrlReceived: we got the File URL from iOS: " << incomingUrl; + QString myUrl; + if(incomingUrl.startsWith("file://")) { + myUrl= incomingUrl.right(incomingUrl.length()-7); + qDebug() << "QFile needs this URL: " << myUrl; + } else { + myUrl= incomingUrl; + } + + // check if File exists + QFileInfo fileInfo = QFileInfo(myUrl); + if(fileInfo.exists()) { + emit fileUrlReceived(myUrl); + } else { + qDebug() << "setFileUrlReceived: FILE does NOT exist "; + emit shareError(0, tr("File does not exist: %1").arg(myUrl)); + } +} + +void IosShareUtils::handleHttpsUrlReceived(const QUrl &url) +{ + if(url.isEmpty()) { + qWarning() << "handleHttpsUrlReceived: we got an empty URL"; + emit shareError(0, tr("Empty URL received")); + return; + } + qDebug() << "IosShareUtils handleHttpsUrlReceived: we got the Other URL from IOS: " << url; + + emit otherUrlReceived(url.toString(), "https"); +} diff --git a/sources/shareUtils/platformshareutils.cpp b/sources/shareUtils/platformshareutils.cpp index 4040d72..8ccc3cf 100644 --- a/sources/shareUtils/platformshareutils.cpp +++ b/sources/shareUtils/platformshareutils.cpp @@ -20,8 +20,8 @@ bool PlatformShareUtils::checkMimeTypeEdit(const QString &mimeType) { QString PlatformShareUtils::getTemporaryFileLocationPath() { return QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); } -void PlatformShareUtils::shareText(const QString &text) { - qDebug() << text; +void PlatformShareUtils::shareText(const QString &text, const QUrl &url) { + qDebug() << text << url; } void PlatformShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId) { qDebug() << filePath << " - " << title << "requestId " << requestId << " - " << mimeType << "altImpl? "; diff --git a/sources/shareUtils/shareutils.cpp b/sources/shareUtils/shareutils.cpp index 78a3f0a..3b4a9ec 100755 --- a/sources/shareUtils/shareutils.cpp +++ b/sources/shareUtils/shareutils.cpp @@ -5,7 +5,7 @@ #include "shareUtils/shareutils.h" #ifdef Q_OS_IOS -#include "cpp/ios/iosshareutils.hpp" +#include "shareUtils/ios/iosshareutils.h" #endif #ifdef Q_OS_ANDROID @@ -62,9 +62,9 @@ QString ShareUtils::getTemporaryFileLocationPath() return mPlatformShareUtils->getTemporaryFileLocationPath(); } -void ShareUtils::shareText(const QString &text) +void ShareUtils::shareText(const QString &text, const QUrl &url) { - mPlatformShareUtils->shareText(text); + mPlatformShareUtils->shareText(text, url); } void ShareUtils::sendFile(const QString &filePath, const QString &title, const QString &mimeType, const int &requestId)