本文介绍了如何找出我的.app的实例是否已经运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程式已安装在[应用程式]资料夹中。但我可以复制这个.app文件,并将其粘贴在我的桌面上。当我尝试在我的桌面上运行这个.app文件,我的系统上正在运行两个实例。
我>第一种方式是看看 runningApplications
在 NSWorkspace
。这将返回一个包含每个启动应用程序的字典的NSArray。 NSMutableArray * applications = [NSMutableArray new ];
[applications addObjectsFromArray:[[NSWorkspace new] runningApplications]];
NSLog(@ - >%@,应用程序);
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?
解决方案
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);
这篇关于如何找出我的.app的实例是否已经运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!