calabash / calabash-ios

Calabash for iOS
Other
1.81k stars 369 forks source link

Xcode 7: Unable to set location on real device or iOS Simulator #377

Open mmurali88 opened 10 years ago

mmurali88 commented 10 years ago

UPDATED FOR Xcode 7

I have been working with set_location method to test my location based scenarios, I am able to make it work on the simulator. But I am out of luck when it comes to real device.

XPATH Locations

/Applications/Xcode.app/Contents/Developer

Xcode 5.1.1
Build version 5B1008

0.9.168

Commands I tried

set_location(:place => 'India')
set_location(:latitude => '', :longitude => '')
uia("UIATarget.localTarget().setLocation({'latitude':21.00, 'longitude':78.00})")

Also logs from the console

ScriptAgent[2274] <Warning>: CLSimulation: Couldn't clear simulated locations!
ScriptAgent[2274] <Warning>: CLSimulation: Couldn't append simulated locations!
ScriptAgent[2274] <Warning>: CLSimulation: Couldn't start location simulation! 
ScriptAgent[2274] <Warning>: CLSimulation: Couldn't flush!

only once I got this

ScriptAgent[2252] <Warning>: CLSimulation: Couldn't clear simulated locations!
kernel[0] <Debug>: Sandbox: ScriptAgent(2252) deny mach-lookup com.apple.locationd.simulation
ScriptAgent[2252] <Warning>: CLSimulation: Couldn't append simulated locations!
kernel[0] <Debug>: Sandbox: ScriptAgent(2252) deny mach-lookup com.apple.locationd.simulation
ScriptAgent[2252] <Warning>: CLSimulation: Couldn't start location simulation!
kernel[0] <Debug>: Sandbox: ScriptAgent(2252) deny mach-lookup com.apple.locationd.simulation
ScriptAgent[2252] <Warning>: CLSimulation: Couldn't flush!
jmoody commented 10 years ago

I have confirmed that setting locations does not work on devices.

# neither of these works.
set_location({:latitude => lat, :longitude => lon})
uia("uia.setLocation(#{lat},#{lon})")

todo

jmoody commented 10 years ago

@CodeAccura @krukow

I filed a bug report with Apple after confirming that the problem persists on iOS 8/Instruments 6.0.

Please file a bug with Apple to let them know that this is a problem.

https://bugreport.apple.com

Here is my bug report - http://openradar.appspot.com/radar?id=4964878712307712

Please mention case 17838015 in your report.

yzhong52 commented 9 years ago

Hey @jmoody, any update from Apple so far?

jmoody commented 9 years ago

No. We are looking for alternative ways to spoof the location - perhaps by passing a GPX file.

Any suggestions are appreciated. Apple is probably never going to fix the API.

yzhong52 commented 9 years ago

I tried using GPX file. It works fine under both simulator/device and it is fairly easy to used. But the only thing that makes us don't like about going that direction is we that need to teach the QAs how to use XCode. We think it might be easier to go with Instruments. Also, we spend sometime digging with spoofing GPS location with Bluetooth. By the end, all we know is that Apple does support location via external Bluetooth. However, it only supports a set of known manufactures. So it also kind of becomes a dead end to us as well. If you are interested, feel free to take sometime to look into that see if you find anything interesting. Kind regards. And thanks for the prompt response.

jmoody commented 9 years ago

@yzhong52

Is it possible to pass a GPX to the application at runtime? I am thinking about passing this as an argument to the instrument command-line tool.

Do GPX files get embedded in the app bundle? Could they be embedded?

yzhong52 commented 9 years ago

Is it possible to pass a GPX to the application at runtime? I am thinking about passing this as an argument to the instrument command-line tool.

Yes, it is possible to pass GPX to application at runtime. But I don't know how to pass it to command-line tool though.

Do GPX files get embedded in the app bundle? Could they be embedded?

Yes, they could be embedded in tha app bundle. Take a look at the foolowing screenshot (HelloWorld is the name of the gpx file). You can add more by Add gpx file to project...

screen shot 2015-04-29 at 1 05 29 pm

jmoody commented 8 years ago

Submitted bug: 22780309

Xcode 7 UIAutomation setLocation API is broken on iOS Simulators and physical devices

Opened a forum topic: https://forums.developer.apple.com/message/59898

Report

Summary:

Since Xcode 6, the setLocation API has been broken for physical devices.

Xcode 7 shows the same problems and now the API is broken for iOS Simulators.

Steps to Reproduce:

Reproduced with https://developer.apple.com/library/ios/samplecode/LocateMe/Introduction/Intro.html

  1. Build and install on a simulator or device.
  2. Open Instruments.app > Automation
  3. Launch the app with Instruments.app
  4. Touch "Start"
  5. Choose the default accuracy by touching "Done"
  6. Clear the location privacy alert by allowing
  7. Use the following script to test change the location
// Same result with setLocation()
target.setLocationWithOptions({"latitude":21.00,"longitude":78.0});

Expected Results:

To see a new location in the table view row.

Actual Results:

No new row is added.

I added some logging to the app in:

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation {

I can see the method is being called.

I tailed the logs of a physical device (iPhone 6 iOS 9) and found:

Sep 21 14:38:11 hat kernel[0] <Notice>: Sandbox: ScriptAgent(1498) deny(1) mach-lookup com.apple.locationd.simulation
Sep 21 14:38:11 hat ScriptAgent[1498] <Warning>: CLSimulation: Couldn't clear simulated locations!
Sep 21 14:38:11 hat kernel[0] <Notice>: Sandbox: ScriptAgent(1498) deny(1) mach-lookup com.apple.locationd.simulation
Sep 21 14:38:11 hat ScriptAgent[1498] <Warning>: CLSimulation: Couldn't append simulated locations!
Sep 21 14:38:11 hat kernel[0] <Notice>: Sandbox: ScriptAgent(1498) deny(1) mach-lookup com.apple.locationd.simulation
Sep 21 14:38:11 hat ScriptAgent[1498] <Warning>: CLSimulation: Couldn't start location simulation!
Sep 21 14:38:11 hat kernel[0] <Notice>: Sandbox: ScriptAgent(1498) deny(1) mach-lookup com.apple.locationd.simulation
Sep 21 14:38:11 hat ScriptAgent[1498] <Warning>: CLSimulation: Couldn't flush!

Version:

$ xcrun xcodebuild -version Xcode 7.0 Build version 7A220

jmoody commented 8 years ago

Apple has responded:

There are no plans to address this based on the following:

The Automation Instrument is no longer supported. Please migrate your tests to the XCTest UI Testing feature available in Xcode 7. Thanks!

We are now closing this report.

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

Please be sure to regularly check new Apple releases for any updates that might affect this issue.
dannyZhou commented 6 years ago

My English is poor, sorry.

I hook com.apple.Maps app in jailbroken devices and get private api CLSimulationManager linker

When I call a private api directly

    Class clazz = NSClassFromString(@"CLSimulationManager");
    id cls = [[clazz alloc] init];
    CLLocation * location = [[CLLocation alloc] init];
    [location initWithLatitude:30.3 longitude:30.3];
    [cls performSelector:@selector(setLocationRepeatBehavior:) withObject:location];

Got an error of this.

2018-02-24 09:35:33.341303 MockLocationMap[3506:363510] CLSimulation: Couldn't set location repeat behavior!

But com.apple.Maps call this api successfully.

So? Any suggestions of simulate location?