iOS: Handle application state for application extensions
Change-Id: I97df0f8ecf93e28bfbe9c719922f1ee5ec12b563 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
0587941f6e
commit
286c153583
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#include <qpa/qwindowsysteminterface.h>
|
#include <qpa/qwindowsysteminterface.h>
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
|
#include <QtCore/private/qcore_mac_p.h>
|
||||||
|
|
||||||
#include <QtGui/private/qguiapplication_p.h>
|
#include <QtGui/private/qguiapplication_p.h>
|
||||||
|
|
||||||
@ -57,7 +58,13 @@ static void qRegisterApplicationStateNotifications()
|
|||||||
// Map between notifications and corresponding application state. Note that
|
// Map between notifications and corresponding application state. Note that
|
||||||
// there's no separate notification for moving to UIApplicationStateInactive,
|
// there's no separate notification for moving to UIApplicationStateInactive,
|
||||||
// so we use UIApplicationWillResignActiveNotification as an intermediate.
|
// so we use UIApplicationWillResignActiveNotification as an intermediate.
|
||||||
static QMap<NSNotificationName, UIApplicationState> notifications {
|
using NotificationMap = QMap<NSNotificationName, UIApplicationState>;
|
||||||
|
static auto notifications = qt_apple_isApplicationExtension() ? NotificationMap{
|
||||||
|
{ NSExtensionHostWillEnterForegroundNotification, UIApplicationStateInactive },
|
||||||
|
{ NSExtensionHostDidBecomeActiveNotification, UIApplicationStateActive },
|
||||||
|
{ NSExtensionHostWillResignActiveNotification, UIApplicationStateInactive },
|
||||||
|
{ NSExtensionHostDidEnterBackgroundNotification, UIApplicationStateBackground },
|
||||||
|
} : NotificationMap{
|
||||||
{ UIApplicationWillEnterForegroundNotification, UIApplicationStateInactive },
|
{ UIApplicationWillEnterForegroundNotification, UIApplicationStateInactive },
|
||||||
{ UIApplicationDidBecomeActiveNotification, UIApplicationStateActive },
|
{ UIApplicationDidBecomeActiveNotification, UIApplicationStateActive },
|
||||||
{ UIApplicationWillResignActiveNotification, UIApplicationStateInactive },
|
{ UIApplicationWillResignActiveNotification, UIApplicationStateInactive },
|
||||||
@ -73,16 +80,24 @@ static void qRegisterApplicationStateNotifications()
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize correct startup state, which may not be the Qt default (inactive)
|
if (qt_apple_isApplicationExtension()) {
|
||||||
UIApplicationState startupState = [UIApplication sharedApplication].applicationState;
|
// Extensions are not allowed to access UIApplication, so we assume the state is active
|
||||||
QIOSApplicationState::handleApplicationStateChanged(startupState, QLatin1String("Application loaded"));
|
QIOSApplicationState::handleApplicationStateChanged(UIApplicationStateActive,
|
||||||
|
QLatin1String("Extension loaded, assuming state is active"));
|
||||||
|
} else {
|
||||||
|
// Initialize correct startup state, which may not be the Qt default (inactive)
|
||||||
|
UIApplicationState startupState = [UIApplication sharedApplication].applicationState;
|
||||||
|
QIOSApplicationState::handleApplicationStateChanged(startupState, QLatin1String("Application loaded"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Q_CONSTRUCTOR_FUNCTION(qRegisterApplicationStateNotifications)
|
Q_CONSTRUCTOR_FUNCTION(qRegisterApplicationStateNotifications)
|
||||||
|
|
||||||
QIOSApplicationState::QIOSApplicationState()
|
QIOSApplicationState::QIOSApplicationState()
|
||||||
{
|
{
|
||||||
UIApplicationState startupState = [UIApplication sharedApplication].applicationState;
|
if (!qt_apple_isApplicationExtension()) {
|
||||||
QIOSApplicationState::handleApplicationStateChanged(startupState, QLatin1String("Application launched"));
|
UIApplicationState startupState = [UIApplication sharedApplication].applicationState;
|
||||||
|
QIOSApplicationState::handleApplicationStateChanged(startupState, QLatin1String("Application launched"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QIOSApplicationState::handleApplicationStateChanged(UIApplicationState uiState, const QString &reason)
|
void QIOSApplicationState::handleApplicationStateChanged(UIApplicationState uiState, const QString &reason)
|
||||||
|
Loading…
Reference in New Issue
Block a user