Signing your macOS application

Signing

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 (this is not recommended). Your app must be signed using your Apple Distribution certificate in order to 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.

  1. Select Build Settings > macOS > Sign in the project browser in order to access the associated Inspector Panel:

../../../_images/21-XojoPublish-B.png
  1. From the popup menu, select the desired team. The team you select will determine the ways in which you can build. The Build For popup menu will include some or all of the following options: Development, Direct Distribution, App Store. If you build for Development, the app will only run on your Mac. If you choose Direct Distribution, the app can run on any Mac. This is the best option if you are distributing the app yourself. If you wish to distribute the app through the Mac App Store, you must choose App Store. Choosing Inspect from the popupmenu displays the macOS Developer Certificates Inspector dialog box which can be used to easily get more information about the certificates installed in your Keychain such as when they expire and more. If a certificate displays an Advice button, that means there are tasks that need to be completed in order to be able to use this certificate. Click the Advice button for details. If the certificate displays a Fix button, this means that it is missing its Intermediate certificate. Click the Fix button to download and install the missing certificate into your keychain.

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.

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, see our blog post about code signing.