Skip to content

Commit

Permalink
Merge pull request beeware#1713 from freakboy3742/ios-geo-perms
Browse files Browse the repository at this point in the history
Correct permissions for iOS Geolocation APIs
  • Loading branch information
mhsmith authored Mar 25, 2024
2 parents 20baa07 + 6610b87 commit a147aaf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
1 change: 1 addition & 0 deletions changes/1713.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The configuration generated for iOS apps declaring geolocation permissions has been corrected.
16 changes: 10 additions & 6 deletions docs/reference/platforms/iOS/xcode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/briefcase/integrations/cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def plist_value(obj):
return "<true/>"
else:
return "<false/>"
elif isinstance(obj, list):
children = "\n ".join(plist_value(value) for value in obj)
return f"<array>\n {children}\n </array>"
elif isinstance(obj, dict):
children = "\n ".join(
f"<key>{key}</key>\n {plist_value(value)}"
for key, value in obj.items()
)
return f"<dict>\n {children}\n </dict>"
else:
return f"<string>{obj}</string>"

Expand Down
15 changes: 9 additions & 6 deletions src/briefcase/platforms/iOS/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 17 additions & 0 deletions tests/integrations/cookiecutter/test_PListExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
(True, "<true/>"),
(False, "<false/>"),
("Hello world", "<string>Hello world</string>"),
(
["hello", "world", True],
"<array>\n"
" <string>hello</string>\n"
" <string>world</string>\n"
" <true/>\n"
" </array>",
),
(
{"hello": "world", "goodbye": False},
"<dict>\n"
" <key>hello</key>\n"
" <string>world</string>\n"
" <key>goodbye</key>\n"
" <false/>\n"
" </dict>",
),
],
)
def test_plist_value(value, expected):
Expand Down
8 changes: 8 additions & 0 deletions tests/platforms/iOS/xcode/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
},
),
Expand All @@ -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"],
}
},
),
Expand All @@ -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"],
}
},
),
Expand Down Expand Up @@ -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"],
}
},
),
Expand Down

0 comments on commit a147aaf

Please sign in to comment.