Distributing a macOS App Outside the Mac App Store
Tags: macos
Published: 2022-03-29 09:40:43

This post covers publishing of macOS applications outside the Mac App Store. The different distribution methods are described by [Apple](https://developer.apple.com/macos/distribution/). At this point it is assumed that the decision has been made to distribute outside the App Store.  Distributing installers is not covered however the steps are fundamentally the same.

>**Version**: Xcode 12.4, macOS 10.15.7


## Requirements
Before beginning the app export process, ensure the following are installed and present.

### Xcode 10.2 or later

Although Xcode 10 will work, Xcode adds the secure timestamp from Xcode 10.2.

### Apple ID

To enable automatic signing, Xcode needs to connect to the Developer portal with an Apple ID registered to a Developer account. Your Apple ID must be registered to the same Developer account where the Developer ID came from. This [post](https://dev.to/ajpagente/check-apple-id-is-registered-to-a-developer-account-e72) describes how to check if your Apple ID is setup correctly.

### Developer ID certificate

The Developer ID private key must be installed on your Mac keychain. 

Apple describes a Developer ID certificate as...
>_A Developer ID certificate lets Gatekeeper verify that you’re a trusted developer when a user opens your app, plug-in, or installer package downloaded from outside the Mac App Store._

Only an Account Holder can generate a Developer ID certificate. Once the certificate is generated and the private key exported from the Account Holder's keychain, the exported key (with a .p12 extension) can be installed on any Mac machine.

You can check if you have a Developer ID certificate in your keychain by running the following command from the Terminal.

```
$ security find-certificate -c "Developer ID Application"
```

### Deployment Target

Notarization only works for binaries linked against **macOS 10.9** or later. Set your Xcode project's _Deployment Target_ to at least 10.9

## Archiving
When you are ready to distribute your app, the first step is to archive the application. 

From the Xcode menu, choose **Product > Archive**. The _Organizer_ window launches showing the archive. You are now ready for the next step: notarization.

![Xcode Organizer window showing app archives](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cm7jviirlg45vv2ktj76.png)

## Notarization
[Apple](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution) describes notarization as...
>_Notarization gives users more confidence that the Developer ID-signed software you distribute has been checked by Apple for malicious components. Notarization is not App Review. The Apple notary service is an automated system that scans your software for malicious content, checks for code-signing issues, and returns the results to you quickly. If there are no issues, the notary service generates a ticket for you to staple to your software; the notary service also publishes that ticket online where Gatekeeper can find it._ 


### Start Distribution
From the _Organizer_, click on the **Distribute App** button to start the distribution process. 

### Destination
Though there is an option to export without notarizing, always choose to notarize as notarization enables automated scans of your app. Choose **Upload** in the _destination_ window.

![Xcode Organizer window to choose app destination is upload or export](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5nvgrz773kw8b8xi1ynx.png)

### Signing Option
Choose **Automatically manage signing** in the _signing options_ window.

![Xcode Organizer window to choose automatic or manual signing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qpmcwwfbg958ecp58d0.png)

### Review package content
If the Summary and Entitlements are as expected, click **Upload** to upload the app to Apple's notarization service.

![Xcode Organizer window showing summary and entitlements](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k5hez30l4ccta7x8l3ly.png)

### Upload Complete
You can monitor the upload progress as shown.

![Xcode Organizer window showing notarization upload progress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1leh71lp6wzmtziki149.png)

Once the upload is complete, wait for Apple's notification.

![Xcode Organizer window showing completed notarization upload](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0dichzee1af4nsrs8r9s.png)

### Notarization Complete
You will receive a notification and an email to your Apple ID once the notarization is complete. For this post, notarization only took about 30 mins.

![Notarization notification](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eybfvxeqx62t6i8m2qnc.png)

### Export Notarized App
From the _Organizer_, choose the archive, and scroll down. If the Organizer is closed, open it from the Xcode menu. Choose **Window > Organizer**.

![Xcode Organizer window showing where to find the export button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3i73xrueu9vfwsvgx73e.png)

Click on **Export Notarized App** to save the app to your chosen location.

![Xcode Organizer window showing the export button for a notarized app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1mmtcwsb5y2qjfd55al.png)

You now have an app that can be distributed outside the Mac App Store.

## Verification
### Verifying if an app is notarized
Verifying notarization is not a mandatory step after exporting a notarized app. It can be useful when you have an app or installer package and you want to know if it is notarized. The post on [How to Check if a macOS App is Notarized](https://dev.to/ajpagente/how-to-check-if-a-macos-app-is-notarized-8p4) describes the verification steps.

## References
If you have questions or issues with notarization, Apple's references is a good starting point for investigation.
- [Resolving Common Notarization Issues](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution/resolving_common_notarization_issues?language=objc)
- [Notarizing macOS Software Before Distribution](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution?language=objc)