Disable NSUserDefaults initialization workaround on iOS

Core Foundation would fail to pick up defaults from command line
arguments, as the logic to read the command line arguments was
in the Foundation class NSUserDefaults.

As a workaround, we initialized NSUserDefaults as early as we could,
so that we could use Core Foundation elsewhere in Qt.

As NSUserDefaults is considered a potential privacy risk, and needs
explicit declaration of use for iOS in the privacy manifest, we
disable the workaround for iOS. This should be okey, as the original
issue does not seem to manifest on iOS 17, and was only a problem
in practice when using command line arguments to debug things.

The issue is also seemingly gone from macOS 14.3, but we keep
the workaround in for now, just in case.

Task-number: QTBUG-114319
Pick-to: 6.7
Change-Id: I2c698353673f797756a877a49cfbd8a37367c31e
Reviewed-by: Doris Verria <doris.verria@qt.io>
This commit is contained in:
Tor Arne Vestbø 2024-02-12 16:50:20 +01:00
parent a3eba2378b
commit 6657acf8f5
2 changed files with 4 additions and 0 deletions

View File

@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE
// --------------------------------------------------------------------------
#if defined(Q_OS_MACOS)
static void initializeStandardUserDefaults()
{
// The standard user defaults are initialized from an ordered list of domains,
@ -64,6 +65,7 @@ static void initializeStandardUserDefaults()
Q_UNUSED(NSUserDefaults.standardUserDefaults);
}
Q_CONSTRUCTOR_FUNCTION(initializeStandardUserDefaults);
#endif
// --------------------------------------------------------------------------

View File

@ -32,9 +32,11 @@ static void printLocalizationInformation()
if (!lcLocale().isDebugEnabled())
return;
#if defined(Q_OS_MACOS)
// Trigger initialization of standard user defaults, so that Foundation picks
// up -AppleLanguages and -AppleLocale passed on the command line.
Q_UNUSED(NSUserDefaults.standardUserDefaults);
#endif
auto singleLineDescription = [](NSArray *array) {
NSString *str = [array description];