Question

I am working on UIAutomation. I need to change the location when the app is in background. I have tried following line of code:

var target = UIATarget.localTarget();
UIATarget.localTarget().deactivateAppForDuration(30);
target.setLocation({longitude:77.50, latitude:12.50});

but target.setLocation is not getting called until the app comes to foreground.

Could any one please tell me how I can change the location when the app is in background.

Was it helpful?

Solution

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!

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top