Auto launching the app
Again, one of the main differences between mobile devices and your computer is that your computer is designed to run multiple programs at the same time. Since we have developed a menu bar app, you would expect to have an option to launch your app as soon as you log into your computer.
Doing this manually is a very long, error prone and time-consuming process as it involves creating and embedding a mini app that runs when the user logs in. It took me many attempts and several hours to get this working properly.
There is however an alternative called Launch At Login. The only problem is... it does not support CocoaPods. When I first implemented this functionality I did not want to have to deal with another dependency manager, but after wasting a lot of time I've come to the conclusion that it's worth using a package that does the heavy lifting for you (especially if you are not a native developer!).
Adding a Swift Package manager dependency#
Right off the bat I'm going to point you to the official Apple documentation for Swift dependencies. You will need a GitHub account and your computer should be able to pull repositories from GitHub in order for this work. In my case, I use SSH to pull the repos, so GitHub has my id_rsa public token and I can just clone repositories without giving away my username and password.
So, we are just going to follow the instructions to set up the
LaunchAtLogin dependency (they are in the README). On your menu bar go to
Swift Packages ->
Add New Dependency, copy the GitHub URL, and XCode should download it.
If you have set up GitHub via SSH or have two-step authentication enabled, you might want to change the URL to use
git protocol instead of
ssh - use
[email protected]:sindresorhus/LaunchAtLogin.git. This should allow XCode to use the SSH credentials in your computer to connect to GitHub. Also when adding the library, do not forget to select the macOS target.
Still following the instructions, go to your target's build phases and add a new script phase, make sure it is below the
Copy Bundle Resources phase. Copy the contents indicated in the README file of