3

My app is getting installed in the Application folder. But I can copy this .app file and paste it on my desktop. When I try to run this .app file on my desktop, two instances are running on my system. How do I prevent this?

phant0m
  • 16,595
  • 5
  • 50
  • 82
Advaith
  • 1,087
  • 3
  • 12
  • 31

1 Answers1

3

There could by many ways,

The first way that hit my mind is to look at runningApplications in NSWorkspace. This returns an NSArray containing a dictionary for each launched application. You can loop through the array to see if the app you are looking for is already running.

NSMutableArray *applications=[NSMutableArray new];    
[applications addObjectsFromArray:[[NSWorkspace new] runningApplications]];
NSLog(@"--> %@",applications);
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • 2
    thanks :) even this code works - if ([[NSRunningApplication runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]] count] > 1) – Advaith Dec 07 '12 at 09:44