Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qiosservices.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#include "qiosservices.h"
6
7#include <QtCore/qurl.h>
8#include <QtCore/qdebug.h>
9#include <QtCore/private/qcore_mac_p.h>
10#include <QtCore/qscopedvaluerollback.h>
11
12#include <QtGui/qdesktopservices.h>
13
14#import <UIKit/UIApplication.h>
15
17
18bool QIOSServices::openUrl(const QUrl &url)
19{
20 if (qt_apple_isApplicationExtension()) {
21 qCWarning(lcQpaServices) << "openUrl not implement for application extensions yet";
22 return false;
23 }
24
25 // avoid recursing back into self
26 if (url == m_handlingUrl)
27 return false;
28
29 if (url.scheme().isEmpty())
30 return openDocument(url);
31
32 NSURL *nsUrl = url.toNSURL();
33 UIApplication *application = qt_apple_sharedApplication();
34
35 if (![application canOpenURL:nsUrl])
36 return false;
37
38 static SEL openUrlSelector = @selector(openURL:options:completionHandler:);
39 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
40 [UIApplication instanceMethodSignatureForSelector:openUrlSelector]];
41 invocation.target = application;
42 invocation.selector = openUrlSelector;
43
44 static auto kEmptyDictionary = @{};
45 // Indices 0 and 1 are self and _cmd
46 [invocation setArgument:&nsUrl atIndex:2];
47 [invocation setArgument:&kEmptyDictionary atIndex:3];
48 // Fourth argument is nil, so left unset
49
50 [invocation invoke];
51
52 return true;
53}
54
55bool QIOSServices::openDocument(const QUrl &url)
56{
57 // FIXME: Implement using UIDocumentInteractionController
58 return QPlatformServices::openDocument(url);
59}
60
61/* Callback from iOS that the application should handle a URL */
62bool QIOSServices::handleUrl(const QUrl &url)
63{
64 QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
65
66 // FIXME: Add platform services callback from QDesktopServices::setUrlHandler
67 // so that we can warn the user if calling setUrlHandler without also setting
68 // up the matching keys in the Info.plist file (CFBundleURLTypes and friends).
69 return QDesktopServices::openUrl(url);
70}
71
72QT_END_NAMESPACE
bool openUrl(const QUrl &url)
bool openDocument(const QUrl &url)
bool handleUrl(const QUrl &url)