Is it possible to simulate heading in Xcode? My iOS project tracks the user location and heading while driving. But I cannot test it in simulator because simulator is unable to track heading (no compass hardware).
It is very inconvenient to go out in the field with actual device for each testing session.
I was thinking on the lines of getting a sample GPX file. Do you think GPX file will contain heading information and simulator will be able to use it?
Related
I'm working on a project where it's very often necessary to change the user's location, of course I included all the necessary data to simulate the location from the very beginning of the project. Today Xcode does not pretend to be a custom location, I decided to try to simulate one of the standard locations (for example San Francisco), but when I launch the application on a real device, my real location is displayed on the real device. I tried to run the application on the simulator, but got the same result. I did a clean project, rebooted the real device (iPhone 7), rebooted Xcode but it did not give results. I read a few topics, but they all relate to the fact that the developers did not include the simulation of the location in the scheme. How can I fix this problem? Thank you.
Update: I've updated Xcode, now I'm using Version 9.1 (9B55), but this did not fix this bug. Sometimes (once a week approximately), Xcode refuses to simulate even standard locations from the list (for example San Francisco). Although the menu above the consoles shows that the location simulates.
Info.plist contains
<key>NSLocationWhenInUseUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Turn On Location Services to allow App to show you Events near you.</string>
Update 1: Xcode does not simulate the location only on a real device (iPhone 7), two weeks ago there was no such problem. When I call CLLocationManager to show an alert, this alert on the real device is not shown at all. I repeat, this problem does not always repeat, this can happen once a week, but no methods help to restore this possibility to a working state.
I got the same problem and here's my work around.
You know the Location Services is not working when you don't see the arrow on status bar when you request location. So just turn Location Services off and on again. I guess this is a bug.
Go to Phone Settings > Location Services... then turn it off and on.
Xcode > Debug > Location Simulation
Simulator > Debug > Location > Custom Location (this will take what you set from step 2.)
You should see the arrow on status bar when you request location. If not... try the steps again.
First of everything ... Warning! , read this (from apple):
You are required to include the NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUsageDescription keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, the NSLocationAlwaysUsageDescription key is also required.) If those keys are not present, authorization requests fail immediately.
Anyway, i just suggest make a simple test.
Make sure that you set Allow Location Simulation on the Run Scheme for your Debug Build Configuration on your target-
Run your App, switch to the Map app on simulator (is is the rfirst time you use, make sure you accept allow location dialog). -
Change the location on the location icon on Xcode (see below), and check that the map move to that location-
If everything is ok, the map app must show selected location
If your app is not able to follow same behaviour, maybe you are missing something. Further reading:
About Location Services and Maps
CoreLocation Framework Reference
Cheers.
I have a location based app that provides information for a driving trip in real time. I would like to test that app in device. How can I mock an entire trip without actually driving. I see a solution exists for Android through mock location apps, is there anything similar for iPhone as well? I would appreciate any pointer. Thanks for your help.
Yeah you can create a GPX file and load it in XCode.
When you start debugging an app in xcode on the bottom where the debugging logging is there is the breakpoint |> and || and there you will see a location icon (see image, black icon all the way to the right). Click that and it will give you option to add GPX file. Generate a GPX file of the route you want and when you load it the phone / simulator will automatically go through those points
How can I (or can I) create a GPX file that will run on the IOS simulator and provide course and altitude information?
I have added tags in the hope they might give altitude but no joy there.
The larger issues I am having in dealing with the simulation of locations include:
1. The GPX documentation gives no semantic information;
2. The I am unaware of any documentation on how the IOS simulator responds to GPX files;
3. Many of the links to sites from this board for creating GPX files seem to create files with tags that the IOS simulator seems to ignore.
Thanks
Currently I have to test app and set the different fake GPS locations on real IOS 7 devices. On Android I use 'My Fake Location'. Unfortunately, I didn't find the same app for IOS 7.
Any ideas to solve my problem?
When running in debug mode you can use the little arrow button in the debug area (Shift+Cmd+Y) in Xcode to specify a location. There are some presets or you can also add a GPX file.
You can generate GPX files here manually: http://www.bikehike.co.uk/mapview.php
(from answer: https://stackoverflow.com/a/17478860/881197)
Create a .GPX file with xcode, then specify your coordinates and when your device connected, hit the little arrow button and select your .GPX file.
You can create multiple files and add lots of coordinates to single .GPX file in order to make some kind of route.
Of course ios7 prohibits creating fake locations on real device.
For testing purpose there are two approches:
1) while device is connected to xcode, use the simulator and let it play a gpx track.
2) for real world testing, not connected to simu, one possibility is that your app, has a special modus built in, where you set it to "playback" mode. In that mode the app has to create the locations itself, using a timer of 1s, and creating a new CLLocation object.
3) A third possibility is described here:
https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
Working with GPX files with Xcode compatibility
I followed the link given by AlexWien and it was extremely useful: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html
But, I spent quite some time searching for how to generate .gpx files with waypoints (wpt tags), as Xcode only accepts wpt tags.
The following tool converts a Google Maps link (also works with Google Maps Directions) to a .gpx file.
https://mapstogpx.com/mobiledev.php
Simulating a trip duration is supported, custom durations can be specified. Just select Xcode and it gets the route as waypoints.
xCode is picky about the GPX file it accepts.
But, in xCode you can create a GPX file with the format it will accept:
And then just change the content of the file to the location you need.
you can do it on real device by run device in Debug mode
Click Debug->Simulate Location -> add .gpx file for your location during run time
I had a similar issue, but with no source code to run on Xcode.
So if you want to test an application on a real device with a fake location you should use a VPN application.
There are plenty in the App Store to choose from - free ones without the option to choose a specific country/city and free ones which assign you a random location or asks you to choose from a limited set of default options.
it seems with XCode 9.2 the way to import .gpx has changed, I tried the ways described here and did not do. The only way worked for me was to drag and drop the file .gpx to the project navigator window on the left. Then I can choose the country in the simulator item.
Hope this helps to someone.
There are one solution for fake GPS in ios simulator and real device. we can use GPX file for fake GPS and simulation.
I followed the step by step guidelines of GPX file use in Xcode with simulation.
Here is full step by step guidelines of GPX file use. And also you can download the GPX file Demo from github.
Is it possible to mock a location when using Core Location Manager like you can in Android? I want to do this so we can see simulated behaviors when a user is a different location.
If you are using at least Xcode 4.2 and iOS SDK 5+, you can launch your app and in the simulator you can click the debug menu, then click the location option, the click custom location. You can then enter a custom latitude and longitude. They also have options for Freeway Drive, City Bicycle Ride, and City Run these all emulate the device moving.
You can definitely simulate location on the device if you run from Xcode. After the app compiles, installs, and starts running, find the "Debug Bar" at the bottom of the window (or just above the Console, if you have that showing). There is a small "Location" icon that reveals a menu of locations, plus an option to load a GPX file if you want something more complex. You can also edit your build scheme to include a default location in the Run phase (i.e., for every run, not just when you set the location with the menu in the Debug bar).
One thing to note, if you're using your personal device and not a dedicated development device: the custom location Xcode sets persists even after you disconnect from Xcode. So if you leave your desk with your phone, you may find it still thinks it's in whatever location you simulated; restarting will clear this setting, and allow you to use your device normally.