XCode / iOS simulator: Trigger significant locatio

2019-01-10 04:16发布

Is there a way to manually tell the device to dispatch a significant location change notification that will wake up any applications registered for this notification? This is for testing only, and I realize this private API call would get rejected upon submission to the app store.

9条回答
唯我独甜
2楼-- · 2019-01-10 05:19

So two answers:

A) Hop on a train :-)

B) Use the simulator. In iOS 5.x simulator, there is a debug menu that has a location submenu. Choose freeway drive. This will start the simulator on an imaginary journey down the scenic 280 in Northern California. It gives you everything but the view: your app will get Significant Location Change updates, and will also be launched in the background if it has been suspended.

To verify that you are actually moving, launch safari in the simulator, and go to maps.google.com and click the little track my location button. You should be moving.

Awesome! Now how to debug the lifecycle problem of being launched by the system? Easy! Have xCode wait for your app to be launched to start debugging. From the Scheme menu, choose edit scheme. In the Run Scheme, and the Info tab, for the "Launch" setting choose : "Wait for My.app to launch".

Run your app once in the simulator, so that it starts monitoring for location updates, then force quit it, so that it is suspended. Add a break point in your application did finish launching function, and wait. As soon as your simulator has gone far enough, your application will be woken up, your breakpoint hit, and you are in the money.

But really, the train ride is more fun.

查看更多
Anthone
3楼-- · 2019-01-10 05:19

Depending on your scenario I would suggest two solutions:

  1. Use a Timer or LocalNotification that periodically calls stopMonitoringSignificantLocationChanges followed by startMonitoringSignificantLocationChanges which should trigger a new location to be sent to your code (might be the same Location as before).

  2. Build your own GPS Simulator that you start in debug builds and that will call the same delegate methods like CLLocationManager would do.

查看更多
forever°为你锁心
4楼-- · 2019-01-10 05:20

Well, this is not possible as the application scope is limited to its own space and such kind of notification cannot be generated with Apple Documented APIs list. Of course.. if any undocumented API is used, application will get rejection from apple due to the use of undocumented/private API.

查看更多
登录 后发表回答