UIAutomation : Change location when the app is in background

╄→尐↘猪︶ㄣ 提交于 2019-12-10 03:45:17

问题


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.


回答1:


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!



回答2:


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




回答3:


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




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/22344858/uiautomation-change-location-when-the-app-is-in-background

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