Background Sync
The ContactsManager SDK allows you to synchronize contacts even when your app is in the background. This ensures that your app always has the most up-to-date contact information, even if the user hasn’t opened the app recently.Enabling Background Sync
To enable background sync, you need to:- Configure your app with the proper capabilities and settings
- Call the
enableBackgroundSync()method during app initialization
Platform-Specific Configuration
- iOS
- Android
- React Native
iOS Configuration
For iOS, you need to:- Add the “Background Processing” capability to your app in Xcode:
- Open your app target’s “Signing & Capabilities” tab
- Click the ”+” button to add a capability
- Select “Background Processing” from the list
- Register the background task identifier in your Info.plist:
- Implement background task scheduling in your AppDelegate:
How Background Sync Works
When background sync is enabled, the ContactsManager SDK will:- Register a background task with the system
- Periodically wake up in the background (based on system constraints and heuristics)
- Check for updated contacts on the device
- Synchronize any changes with the server
- Schedule the next background task
- Only changed contacts are synchronized
- Sync frequency is managed by the operating system based on usage patterns
- Network operations are batched to minimize battery impact
- Background tasks respect system constraints for memory and CPU usage
Limitations
Be aware of these platform-specific limitations:- iOS: Background tasks are scheduled at the system’s discretion based on app usage patterns, network conditions, and battery status
- Android: Background operations may be restricted on some devices with aggressive battery optimization
Best Practices
For optimal background sync performance:- Enable background sync early in your app’s lifecycle
- Handle initialization errors gracefully
- Don’t rely on exact timing of background operations
- Test background behavior thoroughly in real-world conditions
- Consider providing a manual sync option for users who want immediate updates