Skip to content

Guard CloudKit startup in non-entitled builds#322

Open
tymrtn wants to merge 1 commit intoTermiT:masterfrom
tymrtn:fix/icloud-sync-crash-unsigned
Open

Guard CloudKit startup in non-entitled builds#322
tymrtn wants to merge 1 commit intoTermiT:masterfrom
tymrtn:fix/icloud-sync-crash-unsigned

Conversation

@tymrtn
Copy link

@tymrtn tymrtn commented Mar 3, 2026

Problem

Flycut can crash when iCloud sync is enabled in builds that do not have valid iCloud entitlements (common in local/unsigned debug workflows).

Root cause

MJCloudKitUserDefaultsSync assumes CloudKit startup is always valid, then proceeds into container/account setup paths that can throw/trap when:

  • container identifier is missing/invalid, or
  • process lacks iCloud container entitlement.

Solution

Harden CloudKit startup in MJCloudKitUserDefaultsSync by:

  1. Resolving a safe effective container identifier (fallback to iCloud.<bundleIdentifier> when needed).
  2. Checking process entitlement (com.apple.developer.icloud-container-identifiers) before enabling CloudKit.
  3. Guarding container creation/account-status calls with nil/exception handling.
  4. Exiting early and cleanly (resume queue + decrement user action) when prerequisites are not met.

Files changed

  • MJCloudKitUserDefaultsSync/MJCloudKitUserDefaultsSync/MJCloudKitUserDefaultsSync.m

Why this is safe

  • No behavior change for correctly signed/entitled builds.
  • Only affects failure paths by preventing crash and skipping invalid CloudKit enablement.

Validation

  • Reproduced original crash scenario in unsigned workflow before fix.
  • After fix, CloudKit startup exits safely instead of crashing.
  • Framework target builds successfully:
    • xcodebuild -project MJCloudKitUserDefaultsSync/MJCloudKitUserDefaultsSync.xcodeproj -scheme MJCloudKitUserDefaultsSync -configuration Debug build

Additional context

Top-level app build on Xcode 26 may hit an unrelated existing project build-cycle warning in this repository; this PR intentionally does not change project build-phase wiring and is scoped only to the CloudKit crash guard.

Closes #321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when enabling iCloud sync in non-entitled builds

1 participant