Files
Kordant/tasks/ios-production/11-background-fetch.md
2026-05-26 16:06:34 -04:00

2.6 KiB

11. Background Fetch & Sync Optimization

meta: id: ios-production-11 feature: ios-production priority: P2 depends_on: [] tags: [performance, background, production]

objective:

  • Optimize background fetch and data sync to keep app data fresh without draining battery

deliverables:

  • Background fetch configuration
  • Efficient sync strategy
  • Battery usage optimization
  • Background task handling

steps:

  1. Configure background fetch:
    • Enable Background Fetch in Signing & Capabilities
    • Set minimum fetch interval (15 minutes)
    • Implement application(_:performFetchWithCompletionHandler)
    • Or use BGAppRefreshTask for iOS 13+
  2. Optimize sync strategy:
    • Sync only changed data (delta sync)
    • Use If-Modified-Since or ETag headers
    • Prioritize critical data (alerts, exposures)
    • Defer non-critical sync (reports, historical data)
  3. Implement background tasks:
    • Use BGProcessingTask for heavy operations
    • Schedule periodic dark web scans
    • Schedule spam database updates
    • Handle task expiration gracefully
  4. Optimize battery usage:
    • Batch network requests
    • Use cellular data efficiently
    • Defer sync until WiFi available (optional)
    • Respect low power mode
  5. Handle push notification sync:
    • Silent push notifications for urgent updates
    • Content-available: 1 for background processing
    • Wake app for critical alerts
  6. Add sync status indicators:
    • Last sync timestamp in settings
    • Sync progress for large operations
    • Offline mode indicator

tests:

  • Unit: Test background task scheduling
  • Integration: Test fetch completion within 30 seconds
  • Battery: Verify minimal battery impact over 24 hours

acceptance_criteria:

  • Background fetch enabled and configured
  • Data syncs every 15 minutes minimum
  • Delta sync reducing data transfer by >50%
  • Background tasks complete within 30 seconds
  • Battery impact <5% per day from background activity
  • Silent push notifications trigger data refresh
  • Low power mode respected (reduced sync frequency)
  • Sync status visible to user in settings
  • No background task terminations due to timeouts

validation:

  • Simulate background fetch → data refreshed
  • Check battery settings → Kordant background activity minimal
  • Receive silent push → app updates in background
  • Enable low power mode → sync frequency reduced
  • Monitor network usage → delta sync working

notes:

  • iOS limits background fetch frequency based on app usage patterns
  • BGAppRefreshTask is modern replacement for performFetch
  • Always call completion handler or setTaskCompleted
  • Background processing tasks require specific entitlements