How to find out if an instance of my .app is already running or not?

微笑、不失礼 提交于 2020-01-05 03:50:46

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/13759688/how-to-find-out-if-an-instance-of-my-app-is-already-running-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!