Skip to content

fix(apple): enable APNs for CloudKit cross-device sync#33

Merged
MatheusKindrazki merged 1 commit into
mainfrom
fix/icloud-sync-push-entitlement
May 31, 2026
Merged

fix(apple): enable APNs for CloudKit cross-device sync#33
MatheusKindrazki merged 1 commit into
mainfrom
fix/icloud-sync-push-entitlement

Conversation

@MatheusKindrazki
Copy link
Copy Markdown
Owner

@MatheusKindrazki MatheusKindrazki commented May 31, 2026

Problema

iCloud sync entre iPhone e Mac nunca funcionou ("nada sincroniza, nunca funcionou"). Links/metadados não cruzam entre os dispositivos mesmo com a mesma conta iCloud, login feito nos dois e ambos via TestFlight.

Causa raiz

O app sincroniza via um CKSyncEngine manual (não o sync automático do SwiftData — cloudKitDatabase: .none é proposital, os dois são mutuamente exclusivos). O CKSyncEngine depende de push silencioso do CloudKit para acordar o app e puxar mudanças de outro device.

Faltava o entitlement aps-environment em todos os .entitlements. Sem ele, registerForRemoteNotifications() (em IOSAppDelegate, FastSharedApp.swift:228) falha em silêncio → o engine nunca recebe push → zero sync.

Containers iCloud iguais nos dois targets, login ok, mesma conta, TestFlight nos dois (CloudKit Production) — só faltava o canal de push.

Mudanças

  • FastSharedApp.entitlements: + aps-environment = production (cobre iOS e macOS — o project.yml aponta o mesmo entitlement pros dois targets). production porque TestFlight/App Store usam o ambiente APNs production.
  • project.yml: + UIBackgroundModes: [remote-notification] — sem isso o push só é entregue em foreground; com ele o iOS acorda o app em background nos pushes do CloudKit.
  • FastSharedApp/Info.plist: regenerado via xcodegen generate.

Validado com plutil -lint (entitlements + Info.plist OK).

⚠️ Requer ação no Apple Developer Portal (fora do código)

Sem isso o build do TestFlight falha ao assinar (entitlement não autorizado):

  1. developer.apple.com → App ID dev.kindrazki.fastshared → ativar capability Push Notifications → Save. Regerar provisioning profile de distribuição se signing for manual.
  2. CloudKit Dashboard: confirmar schema/zona (FastSharedZone / record type ShareLink) deployed to Production (TestFlight usa o env Production).
  3. Subir build novo e testar nos dois devices.

Notas

  • Dados antigos não sincronizam retroativamente (nunca chegaram ao CloudKit) — só registros novos a partir do build corrigido.
  • O .xcscheme modificado no working tree é pré-existente e ficou fora deste PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

Notas de Lançamento

  • Novos Recursos
    • Implementado suporte completo para notificações remotas em segundo plano, permitindo que o aplicativo receba atualizações importantes sem a necessidade de estar aberto
    • Sincronização automática de dados agora habilitada, garantindo que as informações do usuário estejam sempre atualizadas mesmo quando o app não está em uso ativo

iCloud sync between iPhone and Mac never worked because the push
entitlement was missing. The app drives sync through a manual
CKSyncEngine (SwiftData's cloudKitDatabase is intentionally .none), and
CKSyncEngine relies on CloudKit silent pushes to wake the app and pull
cross-device changes. Without aps-environment, registerForRemoteNotifications()
in IOSAppDelegate failed silently, so no records ever synced.

- Add aps-environment=production to FastSharedApp.entitlements (covers both
  iOS and macOS — same entitlement file is shared by both via project.yml).
  production matches the APNs environment TestFlight/App Store builds use.
- Add UIBackgroundModes: [remote-notification] to the app target so iOS can
  launch the app in the background on CloudKit pushes; without it, sync only
  runs while foregrounded.
- Regenerate FastSharedApp/Info.plist via xcodegen.

Requires (out-of-band): enable the Push Notifications capability on the
dev.kindrazki.fastshared App ID and confirm the CloudKit schema is deployed
to Production, then ship a new build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ccc41d9d-cf7a-470d-b49b-0db49872c797

📥 Commits

Reviewing files that changed from the base of the PR and between 96e6c91 and 4bdd9d0.

📒 Files selected for processing (3)
  • apple/FastSharedApp/FastSharedApp.entitlements
  • apple/FastSharedApp/Info.plist
  • apple/project.yml

Walkthrough

O pull request habilita notificações remotas e execução em background para o app FastShared adicionando o entitlement de APNs em ambiente de produção e configurando os modos de background necessários em múltiplos arquivos de configuração Apple.

Changes

Notificações remotas e execução em segundo plano

Layer / File(s) Resumo
Entitlement de ambiente de APNs
apple/FastSharedApp/FastSharedApp.entitlements
Entitlement aps-environment é definido como production, autorizando o app a receber notificações push via APNs em ambiente de produção.
Modos de background para notificações remotas
apple/FastSharedApp/Info.plist, apple/project.yml
UIBackgroundModes com modo remote-notification é declarado em ambos os arquivos, permitindo ativação em segundo plano por notificações silenciosas para sincronização com CloudKit.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 Um coelho que salta pela nuvem,
Notificações remotas em seu caminho,
APNs configurados com cuidado,
Background modes a trabalhar,
CloudKit sincronizando sem parar! ☁️✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed O título descreve com precisão a mudança principal: ativar APNs (Apple Push Notifications) para sincronização CloudKit entre dispositivos, o que é exatamente o objetivo do PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/icloud-sync-push-entitlement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MatheusKindrazki MatheusKindrazki merged commit 9c6a347 into main May 31, 2026
4 checks passed
MatheusKindrazki added a commit that referenced this pull request May 31, 2026
First TestFlight build carrying the CloudKit push entitlement fix (#33).
1.0.1 was the App Review-rejected version; 1.0.2 ships the cross-device
sync fix (aps-environment + remote-notification background mode).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
MatheusKindrazki added a commit that referenced this pull request May 31, 2026
Both Apple release workflows were malformed and had never run:
- apple-production.yml had the APP_STORE_CONNECT_ISSUER_ID env line
  duplicated ~200 times (240 lines) — GitHub rejected it at parse time
  (startup_failure, zero jobs).
- apple-release.yml had a stray EOF_PLACEHOLDER marker at the end and was
  missing the xcodegen step, so xcodebuild archive had no .xcodeproj.

Rewrites:
- apple-production.yml: clean 50-line workflow that generates the project,
  decodes the ASC API key, and runs `fastlane beta_all` (iOS + macOS to
  TestFlight). Env vars now match exactly what the beta_all lane fetches:
  APP_STORE_CONNECT_API_KEY_ID, _ISSUER_ID, _API_KEY_PATH.
- apple-release.yml: drop the stray marker, add Install XcodeGen + Generate
  Xcode project steps before archive.

Unblocks the apple-v1.0.2 TestFlight build (iCloud sync fix #33).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant