-->

Testing custom location with simulator

2019-05-18 06:19发布

问题:

I just spent the last hour searching - thinking that there has to be an answer - and didn't find much, so I'm asking here.

I'm trying to get the sample app Regions to trigger enter and/or exit regions updates via the simulator. I'm familiar with setting a specific latitude and longitude with Debug > Location > Custom Location but that doesn't seem to do much, although it does seem to work in the LocateMe sample app. At this point I don't know if the problem is a limitation of the iOS Simulator or of the way the sample app handles region detection (I'm still rather new to iOS).

I've come across the FTLocationSimulator but I wonder if that's going to help (especially since it seems to mimic the ability to set Custom Locations via the Simulator).

There also doesn't seem to be much in terms of Apple documentation regarding the iOS Simulators ability to set Custom Locations.

回答1:

Add a GPX file to your project and add waypoints to it. When your app is running under simulation use the Simulate Location feature of XCode (the little way-arrow sitting on the debug bar at the bottom) and choose your GPX file. XCode will then start supplying coordinates to your app.

Example GPX file contents:

<?xml version="1.0"?>
<gpx>
  <wpt lat='33.749272' lon='-84.388261'><name>Atlanta, Georgia</name></wpt>
  <wpt lat='42.7335'   lon='-84.5467'><name>Lansing, Michigan</name></wpt>
  <wpt lat='32.361667' lon='-86.279167'><name>Montgomery, Alabama</name></wpt>
  <wpt lat='38.576667' lon='-92.173611'><name>Jefferson City, Missouri</name></wpt>
  <wpt lat='41.590833' lon='-93.620833'><name>Des Moines, Iowa</name></wpt>
</gpx>

Note that the simulator will 'connect the dots' between two waypoints (in the example above it will generate locations along a line between Atlanta, Georgia and Lansing, Michigan.



回答2:

This works for me:

  1. Go into the Settings application in the simulator
  2. Navigate to General -> International -> Region Format -> (Choose a region)
  3. Specify a region

Hope this helps!