3
votes

I have built a CloudKit app with a rather complex record graph to prove our MVP with our customers. Development has been next to flawless and every problem could easily be derived to crappy code.

Now we've deployed our first version of the app. The review process was Kafka like with the review team being unable to login to cloudkit. I had to use the life line of one of our AppleTS questions to get a checklist for the review team to follow (which basically said - log out and login with another iCloud account if the one you are using doesn't work).

We got through the review process and the app is live on the AppStore. But now the real mess starts on my part. I need to fix a couple of bugs but now I cannot access the app if it is built with my debug settings. As a matter of fact there doesn't seem to be any way I can build and run (and get access, aka login, to CloudKit dev environment).

I've found some obscure references on the net talking about setting up my dev and prod environments correctly, but as far as I know I've simply followed the book, and the Apple Docs on Design Tips for CloudKit simply doesn't solve the problem.

In short! How do I manage a Dev environment and a Prod environment in CloudKit after release, and how do I access Dev environment from a build by XCode sent to my device, to continue development after release?

Edit: Realizing that my Question was not clear enough, here comes an attempt to clairify

I can build and run from XCode. When trying to login to iCloud using

self.container.requestApplicationPermission(CKApplicationPermissions.UserDiscoverability) {...}

I get a

CKApplicationPermissionStatus.Denied

status back. No error, just simply a denied state back. Looking at Settings->iCloud->iCloud Drive-> "Look me up by Email" I sometimes find my switch for my app enabled, and sometimes disabled. Trying to switch the switch crashes the Settings app. Even going to www.icloud.com and setting my discoverability settings for my app does not remedy the problem. Reinstalling the app from App Store or Testflight works like a charm, but of course runs towards to Prod environment.

So the question remains; How do I manage my Dev and Prod environments in such a way that I can access (login to, if you like) my Dev environment when developing, while I have an app for sale in the AppStore or production builds in TestFlight for beta testing.

2
Presumably you are not running the app directly from Xcode on your device; if you are then it accesses the dev CloudKit environment. If a developer is sending you an ad-hoc build to install on your device, then when they package the build they are asked if it should access the production or development CloudKit environmentPaulw11
Oh yes, I'm running it directly from XCode.jollyCocoa
Then it will be accessing the development CloudKit environmentPaulw11
That might be so, but your comments still does not solve my problem. I'll rephrase the question, see if it helps: myContainer.requestApplicationPermission(CKApplicationPermissions.UserDiscoverability) allways return a CKApplicationPermissionStatus.Denied state when running from XCode ever since I released the app. Whether this is trying to access the Dev environment or the Prod environment, the result is the same. The expected behavior would be to login to the Dev environment.jollyCocoa

2 Answers

4
votes

How TO USE CLOUDKIT Development OR Production DB in Xcode debugging (using Xcode v 8.2) Not to worry, if you adhere to the following directions, it will insure you will be able to configure Xcode to work with CloudKit and use BOTH the CloudKit Development AND PRODUCTION DB IN XCODE and to deploy your project to the App Store

1) Create an iCloud account on the xcode computer and login to it 2) Configure Xcode to use CloudKit from the the Capabilities tab of the Project “menu” by turning on iCloud and selecting the CloudKit box. Xcode should then automatically generate Provisioning Profiles, etc as is shown by the various boxes being checked in the iCloud tab area 3) Click on the “CloudKit Dashboard” box in order to bring up CloudKit. I don’t know why, but there are times you cannot connect to CloudKit, the sign on screen just keeps asking for your userId and password and gives no error message…..just keep trying and you will eventually be able to connect 4) Develop your Records and Fields Schema in the Development database of CloudKit 5) Use CloudKit in your project by following the many blogs on the net to CRUD data in your project (especially StackOverflow.com) 6) When your project is done being debugged and is working using Cloudkit’s Development database, switch to the Production database in order to debug it, as when you deploy the project to the App Store, the App Store (and TestFlight) only use the Production database.

As usual, the Apple documentation about how and when to use the Production database is often confusing, overly complex, contradictory, out of date, or just downright incomprehensible (i.e. written by programmers). Also, many of the blogs concerning this issue are not up to date with the latest Xcode and iOS releases or just plain wrong.

The following is what I found to work, mostly by trial and error (and thankfully finding some blogs that were correct) by saving (duplicating) the project at various points using Finder when I got a successful build.

When something didn’t work (e.g. Deploying the CloudKit Development DB to the Production DB in the CloudKit IDE) I would then bring back the last project copy that worked and try something different.

By the way, I have learned the hard way to follow this procedure (i.e., duplicate and save project via Finder) before making ANY significant changes to Xcode, iOS, CloudKit, my Xcode project settings (plist, entitlements file, build settings, etc, etc), or significant code changes.

To change to Production database I did the following, duplicating and saving the project after each step along the way…

After successful debugging your project using the CloudKit Development DB (which Xcode configures automatically for you when you turn on iCloud and select CloudKit from the Capabilities tab of the Project settings “menu”). I did the following…..(also make sure you are logged into iCloud on your development computer)

1) I added this to my entitlements file (a file located in the left hand “Project” menu of the Xcode IDE). com.apple.developer.icloud-container-environment  and set it to "Development" Ran on iPhone and it compiled and worked..made a project copy

2) In the CloudKit IDE, I Deployed (select “Deployment” in lower left of CloudKit IDE) the the Development Db SCHEMA to Production (upper right of IDE). This copies ONLY the DB schema but not the actual data. As far as I can tell there is no way to copy the data over from the Development to the Production DB using either CloudKit or Xcode.

3) Then I selected “Production” in the lower left corner of the CloudKit IDE. The CloudKit IDE background color then changes to indicate you are going to be connected to the Production DB. There is NO need to change any code in your project in order to connect to the Production DB.

4) The project then still compiled successfully. BUT, when I ran the project, it STILL connected to the DEVELOPMENT Db

Duplicate, label and save the project using Finder

5) Then I changed “Development” to “Production” as the value of com.apple.developer.icloud-container-environment in the entitlements file of step 1. All the “boxes” still remained checked successfully in the iClould area of the “Capabilities” tab of the Project settings “menu” The project then still compiled successfully. This time when I ran the project IT CONNECTED TO THE PRODUCTION DB!!!

This shows that it IS possible to debug your project in Xcode USING THE PRODUCTION DB by following steps 1-5 above

Duplicate, label and save the project using Finder

6) Go to iTunes Connect and create and configure your project in order to get ready to upload your project to the App Store (make sure all required project icons and screen shots have 1st been created in Xcode of course..(by the way…..the Production DB will only work on an actual Device….it will NOT work in the Simulator….to change back and forth between using the Development DB and the Production DB just change the value of step 1 to Production or Development)

6) Select “Generic iOS Device”, then select “Archive” from the Product menu, then select “Upload to App Store”

3
votes

I was stuck on that issue too couple of days ago. I totally agree with everything @adamsde1 wrote before me, but I would like to share what I did.

So, first things first, I built an app with CloudKit capabilities. It was easy stuff, just an array of objects that could be shared and edited by all app users (Public DB). Assuming that you know how to do that, let us move on to the issue.

As far as I understood, there are two types of databases Development and Production. Development is used (as you might guess) for development and Production for TestFlight and AppStore versions.

To switch your app from Development to Production, you go to Entitlements in Project Navigator and add com.apple.developer.icloud-container-environment row and set its String value to Production. Also, in APS Environment row you need to set String value to production as well.

The next step will be modifying your DB on AppStore Connect. When you enter your Dashboard go to your Container and press the little gear and select Deploy Schema to Production...

screenshot

This solved my issue when the app did not work on TestFlight, but everything was fine while deploying from Xcode. Hope this helps someone too