The Right Way to Create an iCloud-enabled Mac App in Xcode

By · Published · apple, objective-c, xcode, mac, macos

Because I've encountered this problem twice, I'm going to do a little write-up about it. As much for me as for the next person who encounters this problem. In a very un-Apple way, this process is very poorly documented and very un-intuitive from a user-developer standpoint. Everything that's here, I've culled from Googling about aimlessly and finding on Stack Overflow.

*Symptom: *You create a new app in Xcode with no changes and launch it. It launches just fine. You then go to the target summary settings and click "Enable Entitlements" and have an iCloud key/value store and or containers. Now you launch it and nothing happens. Nothing appears, but Xcode still thinks the app is running.

*What's Happening: *To understand what is happening, you have to go have a look in the Console application (note, the actual system Console.app, not the debug console in Xcode). Open that up and select "All Messages". Look for something that looks like this:

1/28/12 7:49:03.945 PM taskgated: killed <your app ID>[pid 43838] because its use of the com.apple.developer.ubiquity-container-identifiers entitlement is not allowed

What's happening is that taskgated is killing your app because it's not properly signed to use iCloud. And for some reason that is not entirely clear to me, the app being killed is not at all reported back to Xcode - Xcode thinks the app is running. So you just sit there waiting for something to happen with no clue that this sinister lurking background process has killed your app.

How to fix it:

There are two ways you can go from here to fix this. The first and easiest, if you are just turning on entitlements and aren't intending to use iCloud, you can just remove the iCloud Key/Value Store and iCloud containers from the target summary. After doing this, it should work.

But, if you are making an iCloud-enabled app, there's a long list of things you need to do. First, understand that you need to be a paid member of Apple Developer Program.

  1. Log into ADC. Go to the Mac Dev Center, and the Developer Certificate Utility.

  2. Create an App ID by going to App IDs and clicking the Create App ID button in the upper right.

  3. Enter the name of your app and the bundle identifier. It usually looks something like "com.company.app". Click Continue. Your app ID should be entered.

  4. Click the App ID you just entered, then click "Enable for iCloud." Click save.

  5. Next, go to Certificates. If you haven't created any certificates yet, click "Create Certificate" in the upper right and follow the directions. Note, you need both a development and an application certificate.

  6. Next, go to Systems. Be sure you've added your Mac (and, for good measure, any others you'll use for development).

  7. Finally, go to Profiles.

    1. Click Create Profile in the upper right.
    2. Select "Development Provisioning Profile"
    3. Give it a name.
    4. Select the app you created in step 3.
    5. Select the certificate you want to use.
    6. Select the systems you want to use (I did all).
    7. Click "Generate" It may take a few seconds, then it will give you a download.
    8. Open the downloaded profile. It will open in the "profiles" preference pane (which doesn't seem to appear until you try to install a profile). Click install.
  8. Now, in Xcode:

    1. Go to Window > Organizer.
    2. Select "Devices" on the top, and "Provisioning Profiles" on the left.
    3. At the bottom, select "Automatic Device Provisioning" at the bottom, and click "Refresh". If you've never done this before, you'll need to log in with your ADC username and password.
    4. Give it a second, it should pull in your profiles.
    5. Go to your project, select your app target and select "Build Settings." Scroll down to "Code Signing." You may need to go to "All" from "Basic" in the predicate selector.
    6. Under Code Signing Identity, select the dev profile you just created. Note: don't use the wildcard one - it doesn't seem to work.

Whew. Now, if everything went as planned (and you sacrificed a goat to Tim Cook and Tim found your sacrifice pleasing) you should be able to launch your app with no errors.

But help! I got a weird failure on build!

If you get a failure on build that looks like this:

Command /usr/bin/codesign failed with exit code 1

Then it is possible that your developer certificate is set to "Always Trust" in Keychain. It needs to be set to "System defaults" for reasons that escape me entirely.

Note, this may not be entirely accurate and may even be cargo-cultish. But I've encountered this "issue" twice now (once in December, and once now) so I decided to write down my steps so that, in a few months when this befuddles me again, I'll know where to look for the answer.

( Comments )

Did something I wrote help you out?

That's great! I don't earn any money from this site - I run no ads, sell no products and participate in no affiliate programs. I do this solely because it's fun; I enjoy writing and sharing what I learn.

All the same, if you found this article helpful and want to show your appreciation, here's my Amazon.com wishlist.


Related Posts

App Store Entitlements, and the Crippling of an App

Xcode 4


comments powered by Disqus