Handling Alerts on App Startup

Hello,

I’m having an issue with an App that I’m working with. When the App launches the first thing it does it alerts user confirmation for usage of GPS. When launching the app in Appium, Appium states that its waiting for the app to launch and then will timeout and restart the app. Sometimes it only restarts once, sometimes a few times, before it taps the ‘accept’ alert key.

The code seems to be working on subsequent launches but always fails the first time through. The main issue is this line:
info: [debug] [INST] 2014-12-29 20:58:59 +0000 Fail: Could not start script, target application is not frontmost.

Has anyone ever dealt with this and if so have any recommendations?

LOG:

info: [debug] [INST] Waiting for device to boot...
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 5.443 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 1.611 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 1.082 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 0.945 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 0.599 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 1.054 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: --> GET /wd/hub/status {}
info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: <-- GET /wd/hub/status 200 1.274 ms - 184 {"status":0,"value":{"build":{"version":"1.3.2-beta2","revision":"c28942bdd0f377b14ab6b88a268760d08f9ad2fc"},"isShuttingDown":false},"sessionId":"8f1a0a0e-1e64-467c-bf9b-ff5d0461b47f"}
info: [debug] [INST] 2014-12-29 20:58:59 +0000 Fail: Could not start script, target application is not frontmost.