4

Upon initial launch of my app, I get a permissions alert asking if I will allow the app to use my current location. My onAlert method successfully dismisses the alert on my device. When I run it on the simulator, it never gets called. Other internal alerts are handled by the onAlert method on the simulator. The permission alert coming from SpringBoard is not handled on the simulator. Any ideas?

UIATarget.onAlert = function onAlert(alert)
{
    var title = alert.name();
    UIALogger.logMessage(title);
    return false;
}
Jules
  • 14,200
  • 13
  • 56
  • 101
landerton
  • 119
  • 1
  • 6
  • what if you delay "polling the location" of the device? – Nitin Alabur Jan 22 '13 at 03:17
  • checkout http://stackoverflow.com/questions/13938537/how-to-deal-with-the-appname-would-like-to-use-your-current-location-alert-t/13943668#13943668 for more details – Shaun Jan 22 '13 at 07:30

3 Answers3

1

This problem happens because the alert you're seeing comes from the system itself -- before the app actually launches and your automation environment is initialized.

To see this happen, add a debug line before the function definition for UIATarget.onAlert:

UIALogger.logDebug("Now setting up the alert function");
UIATarget.onAlert = function onAlert(alert) {}

Next, Reset Content and Settings... on your simulator and re-run your automation. You should notice that the debug line will not appear until after you manually dismiss the alert about using the current location.

I do not see how this would be fixable from javascript code. You have to delay the alert until the app has properly launched, or follow the example shown in this answer.

Community
  • 1
  • 1
Ian
  • 11,280
  • 3
  • 36
  • 58
0

If default handler is not working for you, then you can simply use 'return true' instead of the 'return false' so that you can manually dismiss the popover. Before 'return true' statement you can write some statement for tapping the button (dismiss button) you wish to.

San27
  • 223
  • 2
  • 7
  • The problem with that is I can't seem to access the alert. UIATarget.localTarget().frontMostApp().alert() is invalid because the alert is not coming from my app. It is coming from SpringBoard. – landerton Jan 22 '13 at 17:21
0

I had the same problem with an app that presents an alert immediately after launching. When I logged the element tree, I could see the additional alert window, and I could let UIAutomation tap the OK button in the alert. But the alert handler was never called.
The reason was that the alert appeared before UIAutomation was set up properly to handle it. If I delayed the presentation of the alert, UIAutomation did catch it.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116