Run Mac App with CloudKit connected to the Production environment - xcode

Has anyone succeeded to run a Developer ID signed Mac App with CloudKit and with access to the Production environment, using Xcode 8 beta 3? According to this diagram of Apple it should be possible, but all my attempts lead to crashes. What are the exact steps to follow?
My attempts until now includes the use of a "Mac DirectDistribution" Provisioning Profile that points to an App ID with CloudKit enabled and with access to an iCloud Container.
My CloudKit enabled-app works perfectly with a standard App Store configuration, but I want to test it with a Production environment.

Just add the following entry to your entitlement plist and do a clean build (shift+command k). No other action is needed: (string to copy: com.apple.developer.icloud-container-environment)

After countless experiments I found the following working solution to test CloudKit on the Mac with Production data, using Xcode 7.3:
In your App project, choose Developer ID in Targets > Identity > Signing
In the Entitlements file add a new line with key "com.apple.developer.icloud-container-environment" with value "Production"
Run the App (debug modus)
Export the app to an Archive, choose Export and select "Export as a Mac Application" to produce a Developer ID-based release version.
The steps are more or less the same if you use Xcode 8, but you have the extra option to disable the App Sandbox.

For Mac the easiest way is to just after Archive click Distribute App then choose Development and click next then choose your iCloud Environment (Production/Test) and save the app wherever you want. This version will access your production iCloud.
enter image description here
enter image description here

Related

How to upload to Apple's My Apps from a Xamarin project

I specifically need help getting the app build into my apps. I am so new to the MAC ecosystem. I need to get my app build from my windows 10 box (parallels) running VS2017/Xamarin Forms project uploaded to My Apps. What i have found is helpful if you are using xcode on the mac.
I have read tons of pages and help files and with all of that what I have includes:
created an app in VS2017/Xamarin that runs happily on the emulator from the MAC (MacBook Pro)
purchased the app dev subcription from apple
created a Production certificate (I don't need this yet but I was in there so...)
created a Development certificate
created a key pair from the Dev cert (that show up in the keychain)
created an App Group
created my app's placeholder under My Apps on App Store Connect
added my iPhone to devices via connecting to the Mac getting the UDID from iTunes
created a development provisioning profile for my iPhone (Not sure how this helps my testflight plight)
Assumptions
You must submit for review the same way for both TestFlight and Prod release to the actual store.
You don't need to open the app in xcode outside Xamarin
There is a tool or concept I am missing out on.
For development outside of Xcode, you will want to use Apple's Application Loader App to upload your app to App Store Connect.
As I said in comment to Matt below his correct answer to my actual question above, I needed to get the project right to get to that point.
Here are the more intimate details for the lurkers. I hope this helps some of you.
I was getting, or trying, to get all of this in place manually instead of letting VS do it's work getting this stuff together while I got to coding. FastLane FTW
Open the account management window, go to Tools > Options > Xamarin > Apple Accounts
Add your AppleID
Click on your appleID
Click the add button
Select your id in the lower text area
then add your distro cert. As is proper you deploy to TestFlight as a prod release.
Then get over to to your iOS project properties:
Make sure that your project is outputting an IPA. (Not Beer ;) )
These are my settings that worked. There could be other configurations that work as well.
I never get the automatic provisioning to work. And while this bundle signing settings look like it will not work, it does. I have received my apple approval for beta and users are in testflight.
Also, make sure you update the version of the app in the plist for subsequent releases. This change is not carried through from the AssemblyInfo.cs as one might expect. viola.
If you see this during debug make sure your debug version has Developer (Automatic) set for your debug settings.
FWIW - My VS2017:
While this does not perfectly match the info # https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/apple-account-management?tabs=windows it worked for me. That page was key to the solution and deserves citing. Your mileage may vary.
If I missed something please reach out and I will update this.

Distributing Apps Outside the Mac App Store crash with Code Signature Invalid error

I have a Mac App for OS X 10.10 that I am trying to create a working release build.
Not for the Mac App store "Distributing Apps Outside the Mac App
Store"
Uses "Developer ID Application" for the release code signing. Things look good in my App dev account
Created an OSX APP ID com.blah.app
Can create and verify an Archive successfully
sudo spctl --assess --verbose=4 Name.App, looks good "Name.App : accepted
source=Developer ID"
Read thru Apple "Distributing Apps Outside the Mac App Store"
Needs to be OS X 10.10 due to customer requirements
Read through everything I can find on stack overflow regarding this
matter
Can build and release iOS without a second thought, but this is my
first Mac App
I run the App and in the console I see "EXC_CRASH (Code Signature Invalid)"
Stumped ...
Gatekeeper
Macs have a "gatekeeper" feature that can be set in 3 modes in System Preferences > Security & Privacy > General > "Allow apps downloaded from:".
Which is your test system set to ?
Since you're signing using a Developer ID, it needs to be set to the 2nd or 3rd option (not just allowing the App store). [2nd option is the default on freshly installed machines]
Build for distribution outside of the app store
Builds that you create for submission to the App store cannot be run by everybody. One needs to build it specifically for that.
To quote https://developer.apple.com/library/mac/qa/qa1884/_index.html :
[...] use Xcode Organizer > Export > Export a Developer ID-signed Application. Developer ID-signed apps can be run by anyone. However, code that uses technologies only available to Mac App Store apps, such as receipt validation, iCloud, and push notifications, will not work if your app is Developer ID-signed. You might need to temporarily disable those parts of your app if you opt for the Developer ID testing approach
There was an error in the selected capabilities (red) that wasn't stopping the build, "Key chain sharing" in this case. Turned off as I didn't need it and everything works as expected

Provisioning: Install a Mac app with iCloud for testing

I am working on a Mac app which works with iCloud KVS & CloudKit container of my iOS app which is already in production. All works fine when I run the app from Xcode directly. However, I need to Archive > Export and move it to the /Applications folder because that's how the system picks up Safari Extension Companion.
But when I try to run the exported app, it immediately crashes and the following error is printed in Console:
When exporting the app, I tried to choose between Development-signed Application (as required here in the CloudKit docs) and Developer ID (as required in SO answer linked above), also between iCloud Development / Production modes. I tried to recreate Certificates and provisioning profiles, making sure that I have iCloud enabled for my App ID (and iOS container is selected).
When I do export, there are a few folders titled "A" and I don't remember having them before enabling iCloud for my project:
What am I missing here? Thanks!

iCloud set up and provisioning

I am trying to set up iCloud within my iOS application, I have done the following:
Removed all old certs on mac.
Added iCloud to the App in Dev Console - created new container and added to app
Redone the dev provision and downloaded
Installed the provision
Added the iCloud Entitlement to the app
And this is where is all goes wrong...
I can't get the app running again, the app is building but I am getting an error saying:
The entitlements specified in your application’s Code Signing Entitlements file do not match those specified in your provisioning profile.
(0xE8008016).
Any ideas??
UPDATE: I have managed to be able to run the application to get everything programmed and put in place, everything is set up iTunes Connect end, all provisions are valid and sync'd.
Now I am getting errors during validation...
There are 4: Invalid Code Signing Entitlements. Your application bundle's signature contains code signing entitlements that are not supported by iOS. Specifically, key 'com.apple.developer.icloud-container-identifiers' in Payload ------- not supported
Other 3 are similar for other containers!
Maybe it's a late comment, but I post it here in case that somebody is struggling for the same reason.
I encountered this issue on Xcode8 recently when I was trying to archive. Generally, I enabled iCloud with Xcode in following steps:
Enable iCloud inCapabilities panel in my target by setting the toggle to ON.
Check iCloud under my App Identifier in Member Center turns green automatically, and a iCloud container is created automatically with my App Identifier. (Apple's system does this for us.)
Regenerate my certificate with my App Identifier.
Create a new provisioning profile.
Download and install the new certificate and provisioning profile
Select the new provisioning profile in Signing(Release) section in General panel in my target.
Then I got errors like:
Provisioning profile "iCloud Test" doesn't include the com.apple.developer.ubiquity-container-identifiers,
com.apple.developer.icloud-container-identifiers,
and com.apple.developer.icloud-services entitlements.
Code signing is required for product type 'Application' in SDK 'iOS 10.1'
Code signing is required for product type 'Application' in SDK 'iOS 10.1'
At last I found that there were two options in iCloud section under my App Identifier in Member Center. By default, the Compatible with Xcode 5 was selected, but I succeeded by selecting the other option.
If you're just adding iCloud to an app for the first time or want to upgrade to use CloudKit after using an older iCloud container:
Go to the Apple Development Center.
Choose Certificates, IDs & Profiles.
Use the dropdown on the top left to switch between iOS/tvOS/watchOS or macOS
Choose App IDs under the Identifiers section.
Choose your app from the list.
Scroll down to iCloud and make sure it is enabled with a green dot.
If it's not enabled or has a yellow dot, click the button at the bottom of the page to Edit and make sure you've checked iCloud service.
You may also need to create a container under the iCloud Containers section then associate it with this app.
After submitting a report to Apple, it turns out that Apple systems are useless AGAIN!
Ok, so if you are creating a NEW application or you are only just adding iCloud to your application - you will need to make sure the system doesn't pick up or create a iOS8 cloud container!
If it does you need to remove it from your app entitlements file, remove the selected containers in the Apple Developer Console and re-download certs again!
Thanks Apple again!
I got blamed for using pre-released software! I haven't touch Xcode 6 yet!!!
What I did:
- leave only com.apple.developer.icloud-services in entitlements file
- in Capabilities under iCloud marked key value storage and iCloud Documents (cloud kit EMPTY)
- Containers set to specify custom but do not select any of your containers
- This will probably give you RED warning sign under steps but leave it as it is DO NOT FIX
- Regarding provisioning profile Development and Distribution profiles have to have App ID which has iCloud enabled but NOT linked to any container
- In those provisioning profiles set under iCloud OLD version for Xcode 5 etc. not a new one related to iCloud containers
I had an error of "Add iCloud Containers to your App ID".
Automatic signing was unable to resolve an issue with target's entitlements.
I don't even use iCloud Containers, only Key-value storage(keychain).
I also switched in iCloud section under my App Identifier in Member Center from "Compatible with Xcode 5" to "Include CloudKit support (requires Xcode 6)" problem still remains.
So I fixed it like this:
Enable iCloud Capabilities panel in my target by setting the
toggle to ON.
Turn on "Include CloudKit support (requires Xcode 6)" in Member
Center (still got same error).
in Xcode in iCloud Capabilities TURN ON CloudKit (even if you don't
need it) and then turn OFF.
And then problem solved for me!

Could not launch 'app' with iCloud container

I have an OS X app targeting 10.7 (Lion) platform. I use XCode 4.4 on a development machine where iCloud is enabled. The OS X version on this machine is 10.8 (Mountain Lion).
I have an APP ID that I enabled iCloud using the Developer Certificate Utility: com.company.appname. The utility shows a green tick next to iCloud label under description of the App ID.
From XCode Target/Summary tab I enabled Entitlements and added iCloud Container com.company.appname. Of course internally it is preceded by the team id in the Entitlements file: teamid.com.company.appname.
I also have a valid (green ticked) provisioning profile on my Mac with the same id:teamid.com.company.appname.
Derived Data locations is set to Relative from XCode/Preferences.
The app builds OK. But when I run it I get "Could not launch "appname". Permission denied." error.
If I remove the iCloud container id com.company.appname from iCloud Containers list box under Entitlements and build the app, it runs OK. But of course I cannot access iCloud container enabled for the app.
I have been working on this problem for the past 24 hours. I have read the guides; Developing for the App Store, App Sandbox Design Guide, and Entitlement Key Reference inside out. Yet I am stuck. What went wrong?
I am desperate and I will be grateful if you can help me.
I think the most likely problem is that the AppID, the Entitlement and your provisioning profile do not match each other.
This can happen easily if you experiment a lot with those settings. It should work right out of the box if you create a fresh new project with valid settings, but it might get corrupted if you convert, change or edit existing projects.
Do not forget about the 10-digit prefix of your app bundle id. This is required, esp. for iCloud Key-Value-Storage!
Log into developer.apple.com, check the AppIDs tab
Create an AppID if necessary
Check the iCloud settings for this app
Note down the exact app identifier in the form ABCDE01234.com.domain.app
Switch back to Xcode, update your Provisioning Profiles and Entitlements in the "Teams" section of the "Devices" Tab in the Organizer
Go to the project settings, select the app target and search for "Code Sign"
Make sure the correct code signing identity is selected (see the application identifier above)
Go to the summary tab and put in your app ID
Open the Entitlements file and check if the right ID is in there as well.
Then it should work.
Hopefully.
Edit: thought it would be nice to add the link to the app id center:
https://developer.apple.com/certificates/index.action#bundlelist

Resources