UIAutomation : Change location when the app is in background

≡放荡痞女 提交于 2019-12-05 04:30:56

Unfortunately UIAutomation can only automate the application it's attached to. When the application is not "active", it has nothing to talk to. Using lockForDuration, deactivateAppForDuration , etc blocks while it relinquishes control to the system, making your app inactive. While the application is in that state UIAutomation can't send it any more messages. I would recommend filing a radar asking for the ability to set the location while the application is inactive.

When I ran into a similar problem in the past I had to use AppleScript to change the location of the simulator to get the effect I needed.

You have since updated your comments indicating you are testing a navigation application. Well! That's a little different. If you do not ACTUALLY require UIAutomation and were only trying to use it as a way to set the location:

Xcode does allow you to simulate a route using GPX files, and this CAN be used with Instruments.

  1. Find an appropriate GPX file, preferably one that is a track.
  2. Go to the scheme for your project. In the Run action, go to the "Options" tab. Check "Allow Location Simulation" and use the drop down list to add your GPX.
  3. Run your application from Xcode.
  4. ...
  5. Profit!

I think you can use update part in background as service. Though i am newcomer in this world. You can try this. Thanks

Please refer to the background fetch section in this link. Hope this will help you

if you want your app to execute methods in background, you have to enable "background mode" in your capabilities tab of your app. you have to choose a mode, for example "location updates". but be careful: apple has restrictions of what kind of apps are allowed to run in background. the "location updates" mode are only allowed for apps like navigation apps. see the app store guidelines for details.

if you dont set the "background mode" to yes, your app has 5 seconds to finish executing tasks after turning to background and then all tasks will be stopped and never called until your comes to foreground again.

Refer the http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520 for the Background fetch. I hope this helps you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!