Sharing Company
Complete guide to sharing your company with team members using CloudKit sharing.
Overview
TheCompanyApp's company sharing enables real-time collaboration where:
Owners create and share companies with team members
Participants access shared company data on their devices
CloudKit handles synchronization automatically
Security ensures only invited users can access data
Prerequisites
For Company Owners
Before sharing:
✅ Company created and fully set up
✅ Business or Enterprise tier (Free tier cannot share)
✅ Owner device connected to internet
✅ Participants have Apple IDs and TheCompanyApp installed
For Participants
Before accepting:
✅ TheCompanyApp installed
✅ Signed in to iCloud
✅ Received share invitation (link)
✅ Internet connection
Tier Limitations
Free
❌ No
0 (owner only)
Business
✅ Yes
Up to 10
Enterprise
✅ Yes
Unlimited
Upgrade Prompt: If you try to share on Free tier, app will prompt to upgrade.
Sharing Flow (Owner)
Step 1: Navigate to Share Settings
Select Company to share
Settings tab → "Share Company" or "Sharing"
Share settings screen appears (
ShareAppView.swift)
Step 2: Initiate Sharing
First Time Sharing:
Tap "Share Company" button
App creates CKShare if not already exists
What Happens Internally:
The app (ChoosVersionView.swift → createCKShareIfNeeded()):
Enlistment: All existing inventory, orders, contacts, etc. are enlisted into the CKShare zone so participants can see them.
Step 3: Share Controller
iOS presents UICloudSharingController:
Share Options:
Anyone with the link: Any user with link can join
Only people you invite: Requires explicit email invitation
Permissions:
Can make changes: Read/write access (default)
View only: Read-only access (future enhancement)
Invitation Method:
Copy Link: Copy share URL to clipboard
Messages: Send via iMessage
Email: Send via Mail app
AirDrop: Share to nearby devices
More: Any app that accepts URLs
Step 4: Send Invitation
Recommended Method: Messages or Email
Share URL Format:
Message Template:
Step 5: Manage Participants
After sharing, the Share Settings screen shows:
Current Participants:
List of all users who accepted
Shows display name, email (from CKShare.Participant)
Permission level (Can Edit / View Only)
Owner Actions:
Remove Participant: Tap participant → Remove
Change Permissions: Tap participant → Change to View Only
Stop Sharing: Delete entire share (revokes all access)
Participant Status:
Accepted: User has accepted and has access
Pending: Invitation sent but not accepted yet
Accepting Invitation (Participant)
Step 1: Receive Invitation
Participants receive share link via:
iMessage
Email
AirDrop
Any messaging platform
Step 2: Open Share Link
On iOS Device:
Tap the share URL
Safari opens briefly
URL redirects to TheCompanyApp (universal link)
Or prompts to install app if not installed
Universal Link Format: The app handles URLs matching:
Step 3: Accept Share
TheCompanyApp opens and presents acceptance UI:
ContentView.swift detects incoming share:
Acceptance Flow:
Loading State: Progress indicator shown during accept operation (can take 5-30 seconds).
Step 4: Wait for Sync
After acceptance:
CloudKit begins syncing company data to Shared Store
Progress may take 10 seconds to 2 minutes depending on data size
Pull down to refresh if company doesn't appear immediately
Step 5: Create UserPass
Company now appears in list:
Tap the new company
App detects missing UserPass
"Create Account" screen appears
Create your own username/password (see Create User Password)
Credentials saved to your Personal Private Store (not shared)
Step 6: Access Company Data
After creating UserPass:
Full access to shared company
See inventory, orders, contacts, etc.
Changes sync in real-time to all participants
Your UserPass remains local and private
Data Sharing Mechanics
What Gets Shared
When a company is shared, participants gain access to:
✅ Company details (name, logo, address)
✅ Inventory items
✅ Orders and invoices
✅ Dispatch records
✅ Tasks and assignments
✅ Contacts
✅ Warehouse configurations
✅ AccessControl records (for all participants)
✅ Audit logs
What Doesn't Get Shared
Private to each user:
❌ UserPass (username, password)
❌ Personal app settings
❌ Notification preferences
❌ Device-specific state
Sync Direction
Bi-Directional: All participants can:
Create new records (add inventory, create orders)
Update existing records (edit orders, adjust stock)
Delete records (based on AccessControl permissions)
Changes sync to all devices in real-time
Real-Time Sync
CloudKit Push Notifications:
When Owner adds an order, participants' devices get notified
When Participant updates inventory, owner sees change immediately
Handled via
.NSPersistentStoreRemoteChangenotifications
Sync Timing:
Usually instant (< 1 second on good network)
Up to 30 seconds on slow networks
Background sync continues even when app inactive
Permissions & Access Control
Share-Level Permissions
Set in UICloudSharingController:
Can make changes: Full read/write (default for participants)
View only: Read-only access (future enhancement)
App-Level Permissions
Managed via AccessControl entity:
Owner Advantages:
isOwner = truein AccessControlCan manage sharing (add/remove participants)
Can delete company
Full access to all data
Participant Rights:
isOwner = falsein AccessControlCreate and edit company data
Cannot manage sharing settings
Cannot delete company (can only leave)
Future Enhancement: Role-based permissions (Manager, Staff, Viewer) enforced via deptMask and managerMask.
Managing Shared Companies
Viewing Participants (Owner)
Settings → Sharing:
See all current participants
View participant email/name
See when they joined (acceptedAt timestamp)
Removing Participants (Owner)
Settings → Sharing
Tap participant to remove
Tap "Remove"
Confirm removal
Effect:
Participant loses access immediately
Company removed from their device on next sync
Their local data remains until they manually delete app data
Changing Permissions (Owner)
Select participant
Tap "Change Permission"
Choose new permission level
CloudKit updates share permissions
Note: Currently only binary (read/write vs. read-only). Future fine-grained control planned.
Leaving a Shared Company (Participant)
Select shared company
Settings → Sharing
Tap "Leave Company" or "Stop Sharing"
Confirm
Effect:
Company removed from your device
No longer receive updates
Owner can re-invite if needed
Stopping All Sharing (Owner)
Deletes entire CKShare:
Settings → Sharing
Tap "Stop Sharing" (bottom of screen)
Confirm action
Effect:
All participants lose access
Company remains on owner's device (Private Store)
Converts back to private company
Can re-share later (creates new CKShare)
Troubleshooting Sharing
"Cannot Share on Free Tier"
Cause: Free tier doesn't support sharing.
Solution: Upgrade to Business or Enterprise tier in Settings.
"Failed to Create Share"
Cause: CloudKit error, network issue, or quota limit.
Solutions:
Check internet connection
Verify iCloud storage not full
Wait 30 seconds and retry
Check CloudKit dashboard for quota errors
Participant Can't Accept Invitation
Cause: Multiple possibilities.
Solutions:
Verify participant has TheCompanyApp installed
Ensure participant signed in to iCloud
Send share link again (previous may have expired)
Check participant's iCloud storage not full
Company Not Appearing After Accept
Cause: Sync delay.
Solutions:
Wait 1-2 minutes
Pull down to refresh companies list
Force quit and reopen app
Check internet connection
Participant Can't See New Data
Cause: Data not enlisted in share, or sync delay.
Solutions:
Owner: Verify data created after sharing is enlisted
Wait for CloudKit sync (up to 1 minute)
Pull down to refresh in affected tab
Check logs for "ensureEnlistedIfShared" calls
Changes Not Syncing
Cause: Network issue, merge conflict, or store mismatch.
Solutions:
Check internet connection on both devices
Force sync by pulling to refresh
Check Console logs for CloudKit errors
Verify both users have latest app version
Technical Deep Dive
CKShare Creation
File: ChoosVersionView.swift
Share Root
Important: The Companies entity itself is the root of the CKShare:
This hierarchical structure ensures:
All company data is part of the same share
Deleting share removes all related data from participants
Queries automatically scope to share zone
Enlistment Strategy
New records created after sharing must be enlisted:
This automatically adds the new item to the CKShare if one exists.
Related: CloudKit Sharing Flow, Ownership Rules, Shared Store
Last updated