1

My iOS app (the iOS to be exactly) shows an popup asking for permission to use user's location at the first time launching - """ Would Like to Use Your Current Location" with two buttons "Don't Allow" and "OK". I tried: SLAlert *locationAlert = [SLAlert alertWithTitle:@"\"\" Would Like to Use Your Current Location"]; SLAlertHandler *okHandler = [locationAlert dismissWithButtonTitled:@"OK"]; [SLAlertHandler addHandler:okHandler]; but Instruments says "Could not start script, target application is not frontmost."

So how to dismiss this popup with Subliminal? Thanks.

Thanh Pham
  • 2,021
  • 21
  • 30

1 Answers1

0

Subliminal's alert handling system is not loaded until just before your tests start running, so if you're showing that alert at startup (in, say, application:didFinishLaunchingWithOptions:) then Subliminal will not be ready to handle the alert by the time it appears.

There are a couple of ways to handle this. You can simply add a delay to getting the user's current location, when running integration tests. Something like:

_manager = [[CLLocationManager alloc] init];
#if INTEGRATION_TESTING
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [_manager startUpdatingLocation];
});
#else
[_manager startUpdatingLocation];
#endif

Or you can register an app-hook to trigger getting the user's current location, invoke that hook during your tests. If you use an app hook to trigger getting the user's location then Subliminal's alert handling system will definitely be loaded by the time any test invokes that hook.

Jeffrey Wear
  • 1,155
  • 2
  • 12
  • 24
Aaron Golden
  • 7,092
  • 1
  • 25
  • 31
  • However you delay showing the alert, remember that the handler for the alert has got to be added before the alert is shown. For that reason, it might be best to use an app hook like @AaronGolden suggests, and call it right after you add the handler. – Jeffrey Wear Sep 11 '13 at 19:47