Know if the user launched an app

前端 未结 2 901
后悔当初
后悔当初 2021-01-16 09:28

Alright, this title might seem strange, but bear with me. I have an app which can be set on its preferences by the user to launch at login. That means I can expect sometimes

2条回答
  •  野的像风
    2021-01-16 10:19

    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
    }
    

提交回复
热议问题