Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set location permission not working as expected #111

Closed
1 task
pang0018 opened this issue Dec 13, 2022 · 24 comments
Closed
1 task

Set location permission not working as expected #111

pang0018 opened this issue Dec 13, 2022 · 24 comments
Assignees
Labels

Comments

@pang0018
Copy link

Description
When setting the location permission for my app to always or inuse via applesimutils, the app can no longer get the simulators location

If you are describing an issue with brew install:

  • I've run brew doctor and fixed all issues

Steps to Reproduce

  1. Installed my app on simulator
  2. Verified can get location from simulator
  3. close app, run command
    applesimutils --byId EE55BEC3-22D4-47DE-90C9-2D3EAC26C843 --bundle com.yourbind.BindBenefits.mobile --setPermissions "location=always"
  4. Open app and navigate to place in app where location is retrieved from device

Expected Behavior
App should continue to get device location

Environment

  • macOS version: 12.16.1
  • Xcode version: 13.4.1
  • location library: expo-location: 14.3.0

Additional Context
A workaround after step 3 from above is to go to Features -> Location on the simulator menu and change to a different location and then back to the original location I had set. But, obviously, this would not work well with Detox automation testing

@pang0018 pang0018 added the bug label Dec 13, 2022
@fleytman
Copy link

Greetings @asafkorem,

Could you please take a look at the issue and try to fix it if possible? Appium uses AppleSimulatorUtils to handle permissions, and this problem affects everyone who has upgraded their simulators to version 16 and above.

It might be helpful: I've tested idb approve $BUNDLE_ID location and xcrun simctl booted privacy grant location-always and they seem to work correctly.

Thank you for your time and consideration.

@mickmaccallum
Copy link

I just started seeing this after updating to the Xcode 15 GM and running on iOS 17. I was able to work around it by omitting "location" from the permissions I was setting entirely, since I don't need it. I am noticing that this was the same behavior as an issue with the "health" permission on iOS 16, which looks like it was fixed here: #106. Maybe this is the same kind of issue?

@artem888
Copy link

artem888 commented Sep 21, 2023

same here, started reproducing it with Xcode 15, the issue is not only iOS17 for me, fails on 15.5 simulator as well. Command I'm running:

applesimutils --byId <device_id> --bundle <bundle_id> --setPermissions "location=always"

and the error message:

*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[5]. See “applesimutils --help” for usage.

@asafkorem
Copy link
Contributor

I will take a look at this issue next week. Thank you for the report and the information provided.

@asafkorem asafkorem self-assigned this Sep 29, 2023
@Gnative
Copy link

Gnative commented Oct 1, 2023

I'm having the same problem setting location permissions after updating to iOS 17 / iPhone 15 / xcode Version 15.0 (15A240d) / - applesimutils version 0.9.10 / brew doctor / update

applesimutils --byOS 17.0 --byType iPhone\ 15 --bundle rs.contou.contours-development --setPermissions "location=inuse"

All other permissions are able to be set via applesimutils I.E

applesimutils --byOS 17.0 --byType iPhone\ 15 --bundle rs.contou.contours-development --setPermissions "photos=YES"

@asafkorem
Copy link
Contributor

asafkorem commented Oct 1, 2023

@Gnative does iOS 16 and below works for you?
Are you getting error a similar to what mentioned here: #117?

@Gnative
Copy link

Gnative commented Oct 1, 2023

No, I don't have any error being displayed and my issue is only with location permissions, others work fine such as notifications, medialibrary and photos

Setting location permission, or any permissions, with iOS 15.5 is working.
This is handy to know to get my e2e tests running while this is being resolved. Thanks.

applesimutils --byOS 15.5 --byType iPhone\ 13 --bundle rs.contou.contours-development --setPermissions "location=always"

Downloading iOS 16 now to try that as well to cover bases..

To note - originally I also had the same error as artem888 thou that was fixed with updating AppleSimulatorUtils to 0.9.10

@dylanrandle
Copy link

dylanrandle commented Oct 1, 2023

Hello, I am facing a similar issue. I updated to Xcode 15 (and iOS 17) and now location permissions do not seem to be correctly applied (app is requesting location permissions, which breaks my tests). I am using the latest applesimutils version 0.9.10.

@Gnative
Copy link

Gnative commented Oct 1, 2023

@asafkorem I can confirm this issue is only related to iOS 17

iOS 15.5 and 16.4 work as you would expect in setting location permissions as well as the other available permissions

@dylanrandle Same problem as you are experiencing, I'm running my tests against iOS 16 for now, to be able to keep moving.

@dylanrandle
Copy link

It's worth noting that the logs indicate that the permissions are set correctly, and it only seems to affect the location permissions in my case (notifications/contacts are correctly applied).

@dylanrandle
Copy link

Can confirm that using iOS 16.4 resolves my issue.

@freerahi
Copy link

freerahi commented Oct 11, 2023

I am not able to set location permission on XCode 15 iOS 17 simulator, notification and tracking permission are getting set perfectly on iOS 17. Location permission is getting set successfully on iOS 15 simulator on XCode 15 as well as on iOS 16 on previous XCode version so it seems there is a bug only for location permission and only on iOS 17. Applesimutils version latest 0.9.10

@fleytman
Copy link

fleytman commented Nov 15, 2023

#111 (comment)

I still have this error on the simulator with ios 16.4 and applesimutils 0.9.10 version

It appears as follows: if I apply --setPermissions location=always , the application does not load further than the splashscreen (just where the app requests geo permission).

@micahdasMA
Copy link

Even when running on iOS 16.4, using location permissions set to always still fails in my detox tests.

The error output I get is

"applesimutils --byId 122A19D0-9C77-4CB1-81B0-02A767E36997 --bundle com.testapp.staging --restartSB --setPermissions location=always" failed with error = ChildProcessError: Command failed: applesimutils --byId 122A19D0-9C77-4CB1-81B0-02A767E36997 --bundle com.testapp.staging --restartSB --setPermissions location=always
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[5]. See “applesimutils --help” for usage.
 `applesimutils --byId 122A19D0-9C77-4CB1-81B0-02A767E36997 --bundle com.testapp.staging --restartSB --setPermissions location=always` (exited with error code 255) (code=255), stdout and stderr:

16:59:05.104 detox[6187] i
16:59:05.104 detox[6187] i *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[5]. See “applesimutils --help” for usage.

@micahdasMA
Copy link

@asafkorem Has there been any progress on this issue, or any workaround for this? I tried to downgrade my XCode version, but versions <v15 are not compatible with the Sonoma OS so that is not possible for me without downgrading my whole OS, which is not feasible

@rhys-thomas
Copy link

I am also hitting this issue with Location permissions not being set on iOS 17 when setting to 'Always', I am in desperate need of a solution or workaround

@BakkerTom
Copy link

I'm encountering this issue as well. None of the location permission options seem to take. It makes it impossible for use to run our tests.

@asafkorem
Copy link
Contributor

asafkorem commented Dec 19, 2023

Since xcrun simctl supports setting the location, we will use it on Detox and will deprecate this API on AppleSimUtils.

See xcrun simctl location --help, wix/Detox#4301

@micahdasMA
Copy link

micahdasMA commented Dec 19, 2023

Do you have an example of how we can use that to set location permissions for a specific detox test? Or are you just saying that you are working on integrating xcrun simctl into detox instead of relying on AppleSimUtils to set permissions?

@DanW82
Copy link

DanW82 commented Dec 28, 2023

Same problem here. Works on Xcode 14.1 but fails on Xcode 15.1

FAILS - applesimutils --byId mySimID --bundle mybundle --restartSB --setPermissions camera=YES,location=always
FAILS - applesimutils --byId mySimID --bundle mybundle --restartSB --setPermissions location=always
WORKS - applesimutils --byId mySimID --bundle mybundle --restartSB --setPermissions camera=YES

The failures give error:

Got error:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
The operation couldn’t be completed. No such file or directory
No such file or directory

I was using:

  • iOS 17.2
  • appliesimutils 0.9.10
  • mac OS 13.6.3 (also tried Sonoma 14.0 but only for Xcode 15.1)
  • Xcode was the only component that made a difference

EDIT: My original post was incorrect. This exact issue is not on iOS 16. It is only iOS 17. iOS 16 appears to have this issue if using an old version of ASU. I was testing on 2 machines, one of which hadn't been updated.

@DanW82
Copy link

DanW82 commented Dec 28, 2023

@micahdasMA This workaround might be of interest.

EDIT: This is only relevant if you just test against iOS 17.

It basically just running the following before the calling launchApp.
xcrun simctl privacy ${device.id} grant all my.app.bundle

I've quickly tested it and it seemed to work but it's not a great workaround. I think it would be a source of flaky tests and a better solution would be for detox to handle it.
It will work for simple scenario's but if anything slightly complex I expect it will start to fail.
We should probably raise a fresh issue for this as its not the same as the original post which was an issue on Xcode 13, the problem we are having only came about in xcode 15. (I'll do this tomorrow when I've had more of a think about this)

I'll be using it in the short term but will look for a better solution. Our company policy forced Somona 14 to install without warning which in turn forced be to move to Xcode 15 before I wanted too so I don't have any other options at this point in time.

const { exec } = require("child_process");
//before all hook calls launchApp

export const launchApp = async (deleteApp, newInstance, locationPerm, cameraPerm) => {
  await setPermissions();

  await device.launchApp({
    delete: false, //MUST be false for this workaround to work
    newInstance,
    // PERMISSIONS WAS ORIGINALLY SET HERE
    launchArgs: {
      // our launch args
    }
  });

  //CALLING SET PERMISSIONS AFTER device.launchApp WILL FAIL
};

export const setPermissions = async () => {
  // Could be more specific than granting all permisions
  const command = `xcrun simctl privacy ${device.id} grant all my.app.bundle`;
  console.log('**** about to run command device ', command);
  exec(command, (error, stdout, stderr) => {
    // I had some logging here
  })
};

@asafkorem
Copy link
Contributor

asafkorem commented Jan 14, 2024

Hey, in case you're experiencing AppleSimUtils issues with Detox, please upgrade to Detox v20.16. This version resolves this issue for Detox (we've migrated some commands from AppleSimUtils to Xcrun Simctl).

@asafkorem
Copy link
Contributor

For any other use-case (not-Detox), please migrate your location permission command to Simctl.
We will soon deprecate all ASU commands that have support on Xcrun Simctl.

@asafkorem
Copy link
Contributor

location option under --setPermissions command is now deprecated, please migrate to xcrun simctl privacy from the latest Command Line Tools for Xcode.
Check our deprecation update for more details: https://github.com/wix/AppleSimulatorUtils/blob/master/DEPRECATIONS.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests