Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Added code to check if simulator not running & launch it.
Browse files Browse the repository at this point in the history
TODO: still need to loop it back into rest of code path, which assumes simulator runnign
  • Loading branch information
jonchui committed Oct 2, 2013
1 parent e47415a commit 6b51b9d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Fake/SimFinger/FakeFingerAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import "FakeFingerAppDelegate.h"
#import <Carbon/Carbon.h>

static NSString *kiOSSimBundleID = @"com.apple.iphonesimulator";

void WindowFrameDidChangeCallback( AXObserverRef observer, AXUIElementRef element, CFStringRef notificationName, void * contextData)
{
FakeFingerAppDelegate * delegate= (FakeFingerAppDelegate *) contextData;
Expand Down Expand Up @@ -43,31 +45,31 @@ - (void)registerForSimulatorWindowResizedNotification

- (AXUIElementRef)simulatorApplication
{
BOOL isSimulatorRunning = NO;
if(AXAPIEnabled())
{
NSArray *applications = [[NSWorkspace sharedWorkspace] runningApplications];

for(NSRunningApplication *application in applications)
{
if([application.localizedName isEqualToString:@"iOS Simulator"])
if([application.bundleIdentifier isEqualToString:kiOSSimBundleID])
{
isSimulatorRunning = YES;
pid_t pid = application.processIdentifier;

// Not sure why this is getting launched, since it's already running?
// Commenting out, because otherwise this causes my app to try & open a second iOS Simulator
// & show error alerts.
// [[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:application.bundleIdentifier
// options:NSWorkspaceLaunchDefault
// additionalEventParamDescriptor:nil
// launchIdentifier:nil];

AXUIElementRef element = AXUIElementCreateApplication(pid);
return element;
}
}
} else {
NSRunAlertPanel(@"Universal Access Disabled", @"You must enable access for assistive devices in the System Preferences, under Universal Access.", @"OK", nil, nil, nil);
}
if (!isSimulatorRunning) {
// Launch the simulator if it isn't running
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:kiOSSimBundleID
options:NSWorkspaceLaunchDefault
additionalEventParamDescriptor:nil
launchIdentifier:nil];
}
NSRunAlertPanel(@"Couldn't find Simulator", @"Couldn't find iOS Simulator.", @"OK", nil, nil, nil);
return NULL;
}
Expand Down

0 comments on commit 6b51b9d

Please sign in to comment.