From 1b7589a25c66d14ff6873710a3851038d627ef57 Mon Sep 17 00:00:00 2001 From: Lars Schmertmann Date: Fri, 15 May 2020 18:45:05 +0200 Subject: [PATCH] Enable Universal Links on iOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pick-to: 5.15 Change-Id: I05b5bede49f619576dd9ab37444f7cb5fe0f15f0 Reviewed-by: Tor Arne Vestbø --- .../code/src_gui_util_qdesktopservices.cpp | 22 +++++++++++++++++++ src/gui/util/qdesktopservices.cpp | 17 ++++++++++++++ .../platforms/ios/qiosapplicationdelegate.mm | 20 +++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp index b9a8d8d90e6..6527021dd65 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qdesktopservices.cpp @@ -96,3 +96,25 @@ QDesktopServices::storageLocation(QDesktopServices::DataLocation) QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/data/organization/application" //! [6] + +//! [7] +com.apple.developer.associated-domains + + applinks:your.domain.com + +//! [7] + +//! [8] +{ + "applinks": { + "apps": [], + "details": [{ + "appIDs" : [ "ABCDE12345.com.example.app" ], + "components": [{ + "/": "/help", + "?": { "topic": "?*"} + }] + }] + } +} +//! [8] diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 3b86d0c5845..53f84fd24fa 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -250,6 +250,23 @@ bool QDesktopServices::openUrl(const QUrl &url) For more information, see the Apple Developer Documentation for \l{https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/communicating_with_other_apps_using_custom_urls?language=objc}{Communicating with Other Apps Using Custom URLs}. + \warning It is not possible to claim support for some well known URL schemes, including http and https. This is only allowed for Universal Links. + + To claim support for http and https the above entry in the Info.plist file + is not allowed. This is only possible when you add your domain to the + Entitlements file: + + \snippet code/src_gui_util_qdesktopservices.cpp 7 + + iOS will search for /.well-known/apple-app-site-association on your domain, + when the application is installed. If you want to listen to + https://your.domain.com/help?topic=ABCDEF you need to provide the following + content there: + + \snippet code/src_gui_util_qdesktopservices.cpp 8 + + For more information, see the Apple Developer Documentation for + \l{https://developer.apple.com/documentation/safariservices/supporting_associated_domains_in_your_app}[Supporting Associated Domains}. If setUrlHandler() is used to set a new handler for a scheme which already has a handler, the existing handler is simply replaced with the new one. diff --git a/src/plugins/platforms/ios/qiosapplicationdelegate.mm b/src/plugins/platforms/ios/qiosapplicationdelegate.mm index a56c1e45684..c9fcfd23b68 100644 --- a/src/plugins/platforms/ios/qiosapplicationdelegate.mm +++ b/src/plugins/platforms/ios/qiosapplicationdelegate.mm @@ -50,6 +50,26 @@ @implementation QIOSApplicationDelegate +- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray> *restorableObjects))restorationHandler +{ + Q_UNUSED(application); + Q_UNUSED(restorationHandler); + + if (!QGuiApplication::instance()) + return NO; + + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { + QIOSIntegration *iosIntegration = QIOSIntegration::instance(); + Q_ASSERT(iosIntegration); + + QIOSServices *iosServices = static_cast(iosIntegration->services()); + + return iosServices->handleUrl(QUrl::fromNSURL(userActivity.webpageURL)); + } + + return NO; +} + - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { Q_UNUSED(application);