Using CloudKit on macOS App

Harry Ng
macOS App Development
4 min readSep 16, 2016

It’s been frustrating to get this working in production environment. The story started like this…

I have been developing a macOS app as companion with its iOS counterpart. The data has been in sync using CloudKit, so I do expect to connect macOS app to CloudKit as well.

Overall, it’s pretty straight forward to port the code used in the iOS app over to macOS code base. CloudKit starts working like a charm in development environment.

Yet, problem starts to appear when I am trying to distribute a beta release. The starting thought is to distribute the app to something like TestFlight. However, as stated.

Mac apps cannot be tested

Thus, like many other macOS apps, I am going to distribute outside AppStore, and employ a way to allow update check. Here is a list of tools I would need:

  1. Apple Developer ID -> Distribute Apple signed application outside App Store
  2. Sparkle Project -> Software Update Framework for macOS
  3. Connect to CloudKit Production during development phase

Apple Developer ID

As suggested in the following guideline, developer can distribute their apps outside App Store, which is suitable for us to release the beta app.

First thing to notice, only Team Agent can create the certificate for Developer ID, which is inconvenient, but acceptable. In general, to distribute to App Store, I will use the same machine with the same cert to deploy.

The process starts with Product > Archive, a binary is created and shown in Xcode Organizer. The guide suggests to validate against App Store first, and it shows this error to me.

This is the first struggle I have now. Theoretically, aps-environment which refers to Apple Push Service is only available to apps distributed thru App Store.

So I skip this part for now.

Sparkle Project

Without going thru App Store, we need a way to notify users once there are updates.

Sparkle Project is a long time proven framework to perform this. It suggests to build the binary and then code sign using the specified certificate. It uses a run script to run the codesign command after the app is built.

Since I have quite a lot of certificates in the machine from multiple developer accounts, I have to specify the cert to codesign. Otherwise it will come out as error for ambiguous cert choices.

The struggle here is that every developer have different common names for their cents, that means they shall change before running their own builds.

Connect to CloudKit Production

As we have been using the iOS counterpart in production, it will be nice to connect the beta Mac app to the production environment in CloudKit to get the production data in action.

When developing iOS app, we can simply add this setting to the entitlement, and specify using Production CloudKit environment.

When I try to do the same in macOS app, it just does not run. In the console, it gives me the error of code signing.

A recent Apple forum thread (a few days ago) reviews that it is a problem that is solved in Xcode 8. I’m still confirming this, as another stackoverflow thread says it works for Xcode 7.3 as well. It is now still a struggle for me.

--

--