Device registration requires an active AmityClient instance and a valid push notification token. The SDK uses a “last write wins” strategy for device management.
Overview
Device registration is essential for delivering push notifications to your users. The social.plus SDK provides comprehensive device management capabilities across all platforms, ensuring reliable notification delivery while maintaining security and user privacy.Key Concepts
- Device Token: Unique identifier for each app installation (FCM token for Android, APNs token for iOS)
- User Association: Each device can be associated with only one user at a time
- Token Lifecycle: Tokens can change and require re-registration
- Platform Differences: Each platform has unique token requirements and behaviors
Platform Setup Required: Complete the platform-specific push notification setup before implementing device registration:
- iOS: iOS Setup Guide
- Android: Android Setup Guide
- React Native: React Native Setup Guide
- Flutter: Flutter Setup Guide
- Web: Web Setup Guide
Device Registration
Prerequisites
Before registering a device, ensure you have:Active Client
AmityClient instance properly initialized and authenticated
Valid Token
Platform-specific push notification token obtained
User Permissions
Push notification permissions granted by user
Network Access
Active internet connection for registration
Platform-Specific Registration
Device Unregistration
When to Unregister
Unregister devices in these scenarios:User Logout
When user logs out of the app
Account Deletion
When user deletes their account
Privacy Settings
When user disables notifications
App Uninstall
Before app uninstallation (if possible)
Unregistration Implementation
Unlike the registration, unregistering for push does not require the AmityClient instance to be associated with any user, therefore you can unregister the device from receiving push notifications as soon as the AmityClient has been initialized with a valid API key.- if a valid
userId
is passed, social.plus’s backend will stop sending push notifications to this device only if the currently active push notification associated with this device is also associated with that user. No action is taken otherwise. - if no
userId
is passed, social.plus’s backend will stop sending push notifications to this device.
Troubleshooting
Registration Failures
Registration Failures
Common Registration Issues:
- Invalid Token: Ensure token is properly formatted and not expired
- Network Issues: Implement retry logic with exponential backoff
- Authentication: Verify AmityClient is properly authenticated
Token Issues
Token Issues
Token-Related Problems:
- Token Refresh: Handle token changes properly
- Platform Differences: iOS requires APNs token availability
- Timing Issues: Ensure token is available before registration
- Storage Issues: Verify token persistence works correctly
Platform-Specific Issues
Platform-Specific Issues
iOS Specific:
- Requires APNs token before FCM token
- Simulator doesn’t support push notifications
- Debug builds may have limitations
- FCM service account required
- Android 13+ runtime permissions
- Google Play Services dependency
- Platform-specific token handling
- Background message handling
- Proper cleanup of listeners
- Platform channel communication
- Firebase plugin configuration
- State management across rebuilds
Related Resources
iOS Setup Guide
Complete iOS APNs certificate setup and configuration
Android Setup Guide
Android FCM configuration and implementation
React Native Guide
Cross-platform React Native push notification setup
Flutter Guide
Flutter push notification implementation guide
Important: Always test device registration and token refresh scenarios thoroughly before production deployment. Each platform has unique requirements and edge cases.