From 4f36e6ebc883607d93ce6e240224e4b3a985396c Mon Sep 17 00:00:00 2001 From: Scott Harrison Date: Wed, 29 Jul 2026 11:45:21 -0500 Subject: [PATCH] iOS: Fixes to Usage Descriptions --- platform/iphone/Info.plist | 62 +++++++++++------------ platform/resources/CoronaPListSupport.lua | 30 ++++++++++- 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/platform/iphone/Info.plist b/platform/iphone/Info.plist index 334eb7ec7..03e55ca42 100644 --- a/platform/iphone/Info.plist +++ b/platform/iphone/Info.plist @@ -37,36 +37,36 @@ UIStatusBarStyle UIStatusBarStyleBlackTranslucent NSAppleMusicUsageDescription - Set Apple Music description in build settings - NSBluetoothPeripheralUsageDescription - Set Bluetooth Peripheral description in build settings - NSCalendarsUsageDescription - Set Calendars Peripheral description in build settings - NSCameraUsageDescription - Set Camera Usage Description in build settings - NSContactsUsageDescription - Set Contacts Usage Description in build settings - NSHomeKitUsageDescription - Set Home Kit Usage Description in build settings - NSLocationAlwaysUsageDescription - Set Location Always Usage Description in build settings - NSLocationUsageDescription - Set Location Usage Description in build settings - NSLocationWhenInUseUsageDescription - Set Location When In Use Usage description in build settings - NSMicrophoneUsageDescription - Set Microphone Recognition Usage description in build settings - NSMotionUsageDescription - Set Motion Usage description in build settings - NSPhotoLibraryUsageDescription - Set Photo Usage description in build settings - NSRemindersUsageDescription - Set Reminders Usage description in build settings - NSSiriUsageDescription - Set Siri Usage description in build settings - NSSpeechRecognitionUsageDescription - Set Speech Recognition Usage description in build settings - NSPhotoLibraryAddUsageDescription - Set Photo Library Add Usage description in build settings + @APP_NAME@ does not access your Apple Music library. + NSBluetoothPeripheralUsageDescription + @APP_NAME@ does not use Bluetooth. + NSCalendarsUsageDescription + @APP_NAME@ does not access your calendar. + NSCameraUsageDescription + @APP_NAME@ does not use your camera. + NSContactsUsageDescription + @APP_NAME@ does not access your contacts. + NSHomeKitUsageDescription + @APP_NAME@ does not use HomeKit. + NSLocationAlwaysUsageDescription + @APP_NAME@ does not use your location. + NSLocationUsageDescription + @APP_NAME@ does not use your location. + NSLocationWhenInUseUsageDescription + @APP_NAME@ does not use your location. + NSMicrophoneUsageDescription + @APP_NAME@ does not use the microphone. + NSMotionUsageDescription + @APP_NAME@ does not use motion data. + NSPhotoLibraryUsageDescription + @APP_NAME@ does not read from your photo library. + NSRemindersUsageDescription + @APP_NAME@ does not access reminders. + NSSiriUsageDescription + @APP_NAME@ does not integrate with Siri. + NSSpeechRecognitionUsageDescription + @APP_NAME@ does not use speech recognition. + NSPhotoLibraryAddUsageDescription + @APP_NAME@ does not access your photo library. diff --git a/platform/resources/CoronaPListSupport.lua b/platform/resources/CoronaPListSupport.lua index ddd636d82..739ee94ff 100644 --- a/platform/resources/CoronaPListSupport.lua +++ b/platform/resources/CoronaPListSupport.lua @@ -107,6 +107,21 @@ local function getDelegates(tmpDir) return delegates end +-- Replace the "@APP_NAME@" token in every string in the Info.plist with the app's name. +-- The iOS template ships default NS*UsageDescription strings that use it, and it works in +-- build.settings strings too since this runs after those have been merged in. +local function substituteAppName( value, appName ) + if type(value) == "string" then + -- escape "%" in the replacement so gsub doesn't treat it as a capture reference + return (value:gsub("@APP_NAME@", (appName:gsub("%%", "%%%%")))) + elseif type(value) == "table" then + for k, v in pairs(value) do + value[k] = substituteAppName(v, appName) + end + end + return value +end + local function inArray(array, item) for key, value in pairs(array) do if value == item then return key end @@ -217,7 +232,9 @@ function CoronaPListSupport.modifyPlist( options ) -- We process app Info.plists effectively twice, once when the templates are built and once when -- the app itself is built. The meta Info.plist has the place holders prefixed with "TEMPLATE_" -- so when we see that we replace it with the normal placeholders. - if infoPlist.CFBundleVersion == "@TEMPLATE_BUNDLE_VERSION@" then + local isTemplateBuild = (infoPlist.CFBundleVersion == "@TEMPLATE_BUNDLE_VERSION@") + + if isTemplateBuild then infoPlist.CFBundleVersion = "@BUNDLE_VERSION@" infoPlist.CFBundleShortVersionString = "@BUNDLE_SHORT_VERSION_STRING@" else @@ -468,6 +485,17 @@ function CoronaPListSupport.modifyPlist( options ) end end + -- Done last so that strings coming from build.settings can use "@APP_NAME@" as well. Skipped + -- when building the templates themselves, where the app's name isn't known yet. + if not isTemplateBuild then + local appName = options.bundledisplayname or options.bundlename or infoPlist.CFBundleDisplayName or infoPlist.CFBundleName + if type(appName) ~= "string" or appName == "" or appName:match("[%$@]") then + -- no name, or an unexpanded ${PRODUCT_NAME}/@PLACEHOLDER@ from the template + appName = "This app" + end + substituteAppName( infoPlist, appName ) + end + if debugBuildProcess and debugBuildProcess ~= 0 then print("Final Info.plist: " .. json.encode(infoPlist, { indent = true })) end