From f088dba053fd9a3fe06c2288bb4648d6e31a706d Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 25 Mar 2024 13:14:04 +0800 Subject: [PATCH 1/3] Allow for array and dict types in plist templated payload. --- src/briefcase/integrations/cookiecutter.py | 9 +++++++++ .../cookiecutter/test_PListExtension.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/briefcase/integrations/cookiecutter.py b/src/briefcase/integrations/cookiecutter.py index 4c292af18..25c0e5868 100644 --- a/src/briefcase/integrations/cookiecutter.py +++ b/src/briefcase/integrations/cookiecutter.py @@ -89,6 +89,15 @@ def plist_value(obj): return "" else: return "" + elif isinstance(obj, list): + children = "\n ".join(plist_value(value) for value in obj) + return f"\n {children}\n " + elif isinstance(obj, dict): + children = "\n ".join( + f"{key}\n {plist_value(value)}" + for key, value in obj.items() + ) + return f"\n {children}\n " else: return f"{obj}" diff --git a/tests/integrations/cookiecutter/test_PListExtension.py b/tests/integrations/cookiecutter/test_PListExtension.py index 825bf4508..1e5ec5656 100644 --- a/tests/integrations/cookiecutter/test_PListExtension.py +++ b/tests/integrations/cookiecutter/test_PListExtension.py @@ -11,6 +11,23 @@ (True, ""), (False, ""), ("Hello world", "Hello world"), + ( + ["hello", "world", True], + "\n" + " hello\n" + " world\n" + " \n" + " ", + ), + ( + {"hello": "world", "goodbye": False}, + "\n" + " hello\n" + " world\n" + " goodbye\n" + " \n" + " ", + ), ], ) def test_plist_value(value, expected): From 8578dd47c9fe3a0992c4f92ed5fb2d210adcc785 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 25 Mar 2024 13:16:20 +0800 Subject: [PATCH 2/3] Corrected iOS permissions for geolocation. --- docs/reference/platforms/iOS/xcode.rst | 16 ++++++++++------ src/briefcase/platforms/iOS/xcode.py | 15 +++++++++------ tests/platforms/iOS/xcode/test_create.py | 8 ++++++++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/reference/platforms/iOS/xcode.rst b/docs/reference/platforms/iOS/xcode.rst index 84f0aec37..b3c9bbbc2 100644 --- a/docs/reference/platforms/iOS/xcode.rst +++ b/docs/reference/platforms/iOS/xcode.rst @@ -92,12 +92,16 @@ Briefcase cross platform permissions map to the following ``info`` keys: * ``camera``: ``NSCameraUsageDescription`` * ``microphone``: ``NSMicrophoneUsageDescription`` -* ``coarse_location``: ``NSLocationDefaultAccuracyReduced=True`` if ``fine_location`` is - not defined, plus ``NSLocationWhenInUseUsageDescription`` if ``background_location`` - is not defined -* ``fine_location``: ``NSLocationDefaultAccuracyReduced=False``, plus - ``NSLocationWhenInUseUsageDescription`` if ``background_location`` is not defined -* ``background_location``: ``NSLocationAlwaysAndWhenInUseUsageDescription`` +* ``coarse_location`` + - ``NSLocationDefaultAccuracyReduced=True`` + - ``NSLocationWhenInUseUsageDescription`` if ``fine_location`` is not defined +* ``fine_location`` + - ``NSLocationDefaultAccuracyReduced=False`` + - ``NSLocationWhenInUseUsageDescription`` +* ``background_location``: + - ``NSLocationAlwaysAndWhenInUseUsageDescription`` + - ``NSLocationWhenInUseUsageDescription`` if neither ``fine_location`` or ``coarse_location`` is set + - ``UIBackgroundModes`` will include ``location`` and ``processing`` * ``photo_library``: ``NSPhotoLibraryAddUsageDescription`` Platform quirks diff --git a/src/briefcase/platforms/iOS/xcode.py b/src/briefcase/platforms/iOS/xcode.py index 453c036ad..e7cca1a9d 100644 --- a/src/briefcase/platforms/iOS/xcode.py +++ b/src/briefcase/platforms/iOS/xcode.py @@ -271,20 +271,23 @@ def permissions_context(self, app: AppConfig, x_permissions: dict[str, str]): info["NSMicrophoneUsageDescription"] = x_permissions["microphone"] if x_permissions["fine_location"]: + info["NSLocationWhenInUseUsageDescription"] = x_permissions["fine_location"] info["NSLocationDefaultAccuracyReduced"] = False elif x_permissions["coarse_location"]: + info["NSLocationWhenInUseUsageDescription"] = x_permissions[ + "coarse_location" + ] info["NSLocationDefaultAccuracyReduced"] = True if x_permissions["background_location"]: + if "NSLocationWhenInUseUsageDescription" not in info: + info["NSLocationWhenInUseUsageDescription"] = x_permissions[ + "background_location" + ] info["NSLocationAlwaysAndWhenInUseUsageDescription"] = x_permissions[ "background_location" ] - elif x_permissions["fine_location"]: - info["NSLocationWhenInUseUsageDescription"] = x_permissions["fine_location"] - elif x_permissions["coarse_location"]: - info["NSLocationWhenInUseUsageDescription"] = x_permissions[ - "coarse_location" - ] + info["UIBackgroundModes"] = ["processing", "location"] if x_permissions["photo_library"]: info["NSPhotoLibraryAddUsageDescription"] = x_permissions["photo_library"] diff --git a/tests/platforms/iOS/xcode/test_create.py b/tests/platforms/iOS/xcode/test_create.py index 8b7d37b4e..6e9ba9d9a 100644 --- a/tests/platforms/iOS/xcode/test_create.py +++ b/tests/platforms/iOS/xcode/test_create.py @@ -203,7 +203,9 @@ def test_extra_pip_args(create_command, first_app_generated, tmp_path): {}, { "info": { + "NSLocationWhenInUseUsageDescription": "I always need to know where you are", "NSLocationAlwaysAndWhenInUseUsageDescription": "I always need to know where you are", + "UIBackgroundModes": ["processing", "location"], } }, ), @@ -217,7 +219,9 @@ def test_extra_pip_args(create_command, first_app_generated, tmp_path): { "info": { "NSLocationDefaultAccuracyReduced": True, + "NSLocationWhenInUseUsageDescription": "I need to know roughly where you are", "NSLocationAlwaysAndWhenInUseUsageDescription": "I always need to know where you are", + "UIBackgroundModes": ["processing", "location"], } }, ), @@ -231,7 +235,9 @@ def test_extra_pip_args(create_command, first_app_generated, tmp_path): { "info": { "NSLocationDefaultAccuracyReduced": False, + "NSLocationWhenInUseUsageDescription": "I need to know exactly where you are", "NSLocationAlwaysAndWhenInUseUsageDescription": "I always need to know where you are", + "UIBackgroundModes": ["processing", "location"], } }, ), @@ -260,7 +266,9 @@ def test_extra_pip_args(create_command, first_app_generated, tmp_path): { "info": { "NSLocationDefaultAccuracyReduced": False, + "NSLocationWhenInUseUsageDescription": "I need to know exactly where you are", "NSLocationAlwaysAndWhenInUseUsageDescription": "I always need to know where you are", + "UIBackgroundModes": ["processing", "location"], } }, ), From 6610b87906aa1c1545d1376b393e7b011733f878 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 25 Mar 2024 13:43:31 +0800 Subject: [PATCH 3/3] Add changenote. --- changes/1713.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1713.bugfix.rst diff --git a/changes/1713.bugfix.rst b/changes/1713.bugfix.rst new file mode 100644 index 000000000..e56fd9ff6 --- /dev/null +++ b/changes/1713.bugfix.rst @@ -0,0 +1 @@ +The configuration generated for iOS apps declaring geolocation permissions has been corrected.