I am developing an application in cocoa,which needs to check whether that app is already running at start up.If already running then i need to quit the new instance ..Is there any way to do this..Looking for a perfect solution
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It sounds like you are saying you want to keep multiple instances of your cocoa app from running at the same time. Normally cocoa apps do not allow multiple instances to be running at the same time so typically you would not need to perform this check. Is there some specific circumstance in which you are finding that a cocoa app is being run concurrently?
In general, a cocoa way to solve this look at launchedApplications 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. I would advise that you use the value with the key NSApplicationBundleIdentifier which will have a value like “com.mycompany.myapp” rather than looking for the name. If you need to find the bundle identifier for an app you can look at its info.plist file in the app package.