Know if the user launched an app

放肆的年华 提交于 2019-12-01 13:40:21

Although it may depend on how you intend to automate the launch of the app, you could use command line arguments to distinguish between system launch vs. user launch.

So, the command line launch might like like this:

MyApp -autoLaunch "Y"

To parse the command line args in a Cocoa app, you could use NSUserDefaults (Yes, you can!):

if( ![[NSUserDefaults standardUserDefaults] objectForKey:@"autoLaunch"] isEqualToString:"Y"] ) {
    // do something for user initiated launch
}

I don't have an exact answer to your question. However, may I suggest that your app should show the window if the window was visible when the user last quit your app?

This may be more in-line with the Mac UI guidelines' suggestion on restoring apps and windows, and is within the user's expectations.

Also, a user who set your app to launch at login will probably understand to close the window and not have it restored the next time, or make the system also hide your app during login.

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