Signing your macOS application

A feature called GateKeeper was added with the release of OS X 10.8 Mountain Lion in 2012. With this feature new apps that are downloaded or copied to a Mac with OS X 10.8 or newer, but that are not digitally signed using an Apple Developer Certificate, display an error when run: "App" can't be opened because it is from an unidentified developer.

On older versions of macOS, this error can be overridden in System Preferences (Security & Privacy), by changing the "Allow applications downloaded from" setting to "Anywhere". Unfortunately, the "Anywhere" option is no longer available with macOS 10.12 Sierra. Alternatively, you can right-click on the app in Finder and click Open in the menu to indicate, "I'd really like to run this app, thank you very much."

Note that this only matters for new apps that you transfer to a Mac running macOS 10.8 or later. You'll be able to run the apps you create on your developer machine without this warning. You'll only run into this warning when you copy the app to another Mac, either by making it available for download or by copying it via a USB stick, the network or anything else.

So even though you don't technically need to sign your Mac applications in order to avoid this warning, you are probably going to want to. The truth is that most people will just leave the setting at the default and will not know that when they get the warning message that they can right-click on the app to open it. You could try explaining all this to them, but either way it is going to be a hassle for your users. Odds are they just won't bother with your app. The solution is to code-sign your app.

Important

If you do not sign your macOS app, Xojo will sign it for you with ad-hoc credentials. While this will allow to distribute the app to others, your app must be signed with your own App Store credentials be accepted by Apple for inclusion in the Mac App Store.

Getting an Apple developer account

To code sign your apps you need to sign up for the Apple Developer Program, which costs $100 a year.

Installing Xcode and Apple certificates

Before you can distribute apps via the Mac App Store, they need to be codesigned. To do that, you will need to download and install Xcode which you will use to create these certificates. It's not difficult to do and you only need to do it once.

Code signing your app

Now you are ready to code sign your application.

To do this, you'll need your Apple Development certificate ID:

  1. Launch the Keychain Access app.

  2. Click the My Certificates button.

  3. In the list that appears, double-click the item that begins with Apple Development, followed by your name.

  4. In the window that appears, look for the row titled Common Name.

  5. Double-click on the value in parentheses to select it. That is your Apple Development certificate ID.

  6. Select Edit > Copy.

  7. Back in Xojo, go to Build Settings in the Navigator and expand the macOS item.

  8. Click Sign. The Inspector shows the properties for signing.

  9. In the Developer ID field, paste in your Apple Development certificate ID.

Your app will now be signed automatically when you build it.

Now you can compress/package your app and transfer it to another computer for installation.

Note

If you are making your application available to the general public, you will want to notarize it first. This step will prevent the user from having to right-click and choose Open to launch your app for the first time. Utilities such as App Wrapper (see below) provide this functionality.

Code signing must be done as the absolute last step. If you modify anything inside your application bundle (such as Info.plist) after you code sign, you will invalidate the signature and you'll have to code sign again. For a Build Step, this means it must be the last item after the Build item.

Note

If you are building your Mac app from Windows or Linux and have already added your certificate to the project, Xojo will produce a script you can run on a Mac to sign your app. This script is saved in the same directory as your project file.

For more information about code signing from Apple, refer to the macOS Code Signing In Depth Technical Note at the Apple Dev Center.

3rd party alternative

For more complicated code signing situations you might want to consider a 3rd party code signing tool, such as App Wrapper.