Flutter’s cross-platform nature allows you to implement push notifications once and deploy to both platforms, but platform-specific configuration is still required.
Prerequisites
Firebase Project
Active Firebase project with FCM enabled
Platform Setup
Android google-services.json and iOS GoogleService-Info.plist
social.plus SDK
social.plus Flutter SDK properly integrated
Certificates
iOS APNs certificate and Android FCM configuration
Step 1: Install Dependencies
Add the Firebase Messaging plugin to yourpubspec.yaml:
Step 2: Configure Firebase with FlutterFire CLI
Before proceeding with push notification setup, you need to configure Firebase for your Flutter app using the FlutterFire CLI.Follow the official Firebase documentation to install and configure FlutterFire CLI for your platform:The FlutterFire CLI will automatically handle Firebase project setup, app registration, and configuration file generation for both platforms.
Initialize Firebase in Your App
After runningflutterfire configure, initialize Firebase in your app’s main() function:
Step 3: Platform Configuration
If you’ve run
flutterfire configure, the configuration files are already in place. You still need to update the build files and permissions as shown below.Android Configuration
- Add google-services.json to
android/app/(automatically done by FlutterFire CLI) - Update build.gradle files:
- Add permissions to
android/app/src/main/AndroidManifest.xml:
iOS Configuration
- Add GoogleService-Info.plist to
ios/Runner/(automatically done by FlutterFire CLI) - Enable Push Notifications capability in Xcode
- Generate APNs certificate following the iOS setup guide
- Update Runner-Info.plist for background modes:
- Update AppDelegate.swift:
Note: The notification handlers above allow you to:
- Display notifications when app is in foreground (
willPresent) - Handle user taps on notifications (
didReceive) - Access notification payload through
userInfodictionary - Customize notification presentation options
Step 4: Register Device for Push Notifications
After configuring the platform settings, you need to register the device token with social.plus SDK.Implementation
Create a function to handle device token registration:Usage Example
Call the registration function after the user is logged in to social.plus:Important Notes:
- iOS: The function attempts to get the APNs token first, then falls back to the FCM token if unavailable
- Android: Directly retrieves the FCM token
- Permissions: iOS requires explicit permission request, which is handled in the function
- Timing: Register after user authentication with social.plus SDK
Step 5: Upload Certificates to social.plus Console
Android - FCM Service Account
-
Generate FCM service account JSON:
- Go to Firebase Console → Project Settings → Service Accounts
- Click “Generate new private key”
- Download the JSON file
-
Upload to social.plus Console:
- Navigate to Settings → Push Notifications
- Upload the FCM service account JSON file
iOS - APNs Certificate
- Generate .p12 certificate following the iOS setup guide
- Upload to social.plus Console:
- Navigate to Settings → Push Notifications
- Upload the .p12 file with password
Firebase Cloud Messaging (FCM) for iOS
iOS also supports Firebase Cloud Messaging (FCM) for push notifications. To set this up:-
Upload APNS Auth Key to Firebase:
- Go to your Firebase Console
- Navigate to Project Settings → Cloud Messaging → Apple app configuration
- Upload your Apple Push Notification service (APNs) Authentication Key (.p8 file)
- Provide your Key ID and Team ID
-
Upload APNS Certificate to social.plus Console:
- Get your iOS APNs Certificate (.p8 file)
- Go to social.plus Console
- Navigate to Settings → Push Notifications
- Upload your APNs Certificate (.p8 file) with the appropriate configuration
Best Practices
Cross-Platform Considerations
Cross-Platform Considerations
Platform-Specific Handling: While Flutter allows shared code, some platform-specific handling is necessary.
State Management
State Management
Token State Management: Keep token state consistent across app lifecycle.
Error Handling
Error Handling
Robust Error Management: Handle various failure scenarios gracefully.
Troubleshooting
Common Issues
Common Issues
Token Not Generated:
- Verify Firebase configuration files are correctly placed
- Check internet connectivity
- Ensure permissions are granted
- Verify APNs certificate is uploaded to social.plus Console
- Test with TestFlight or App Store build (not debug)
- Check iOS project capabilities
- Verify FCM service account JSON is uploaded
- Check google-services.json placement
- Ensure minSdkVersion >= 21
Platform-Specific Issues
Platform-Specific Issues
iOS Debug Builds:
- Push notifications don’t work with debug builds
- Use TestFlight for testing
- Runtime notification permission required
- Handle permission request properly