Appearance
Push Notifications
Push messaging allows you to keep your users up-to-date and re-engage them with your app after periods of inactivity. Upshot.ai makes it simple to send push notifications through Application Push Notification Service(APNS) and Firebase Cloud Messaging (FCM). Upshot.ai also supports pushing an activity along with the Push.
Overview
The Upshot Flutter SDK provides comprehensive push notification capabilities:
- Rich Media Support - Images, videos, and custom layouts
- Deep Linking - In-app navigation and content targeting
- Custom Actions - Interactive buttons
- Cross-Platform - iOS (APNS) and Android (FCM) support
PushNotifications Module Integration
If PushNotifications Module Already Exists
If push notification module already exists in your project, follow the below steps to support Upshot.ai Notifications as well.
Update Token & Push Click Details
Send Token
dart
import 'package:flutter_upshot_plugin/flutter_upshot_plugin.dart';
// Send FCM/APNS token to Upshot
void updatePushToken(String token) {
FlutterUpshotPlugin.sendDeviceToken(token);
}
Invoke Display Notification
dart
// Display notification when received
FlutterUpshotPlugin.displayNotification(pushBundle);
Send Push Click Details
Upshot.ai provides push notification click reports and ability to send InApp Notifications along with push notifications.
dart
// Handle push notification click
void handlePushClick(Map<String, dynamic> pushPayload) {
FlutterUpshotPlugin.sendPushClickDetails(pushPayload);
}
Fresh PushNotifications Integration
Android Integration
For Android push notifications, you need to configure Firebase Cloud Messaging and update your manifest file.
Manifest Configuration
Add the following metadata and services to your android/app/src/main/AndroidManifest.xml
:
xml
<!-- Push notification metadata -->
<meta-data android:name="UpshotPushSmallIconColor" android:value="#ff0000"/>
<meta-data android:name="UpshotPushSmallIcon" android:value="notification_icon"/>
<meta-data android:name="UpshotAllowForegroundPush" android:value="@bool/bool_true"/>
<meta-data android:name="UpshotShowOtherPushes" android:value="@bool/bool_true"/>
<!-- Push action receiver metadata -->
<meta-data
android:name="BkPushActionReceiver"
android:value="com.upshot.flutter_upshot_plugin.BKPushAction"/>
<!-- Push click receiver -->
<receiver android:name="com.upshot.flutter_upshot_plugin.BKPushAction">
<intent-filter>
<action android:name="com.upshot.flutter_upshot_plugin.BKPushAction" />
</intent-filter>
</receiver>
<!-- Firebase messaging service -->
<service android:name="com.upshot.flutter_upshot_plugin.UpshotFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Android Resources
Create a bool_true
property in your android/app/src/main/res/values/strings.xml
:
xml
<resources>
<bool name="bool_true">true</bool>
</resources>
Custom Notification Icons
- Small Icon: Add your notification icon as
notification_icon.png
in the appropriate drawable folders - Icon Color: Set the desired color using the
UpshotPushSmallIconColor
metadata
Get device token via method channel
Add below lines of code in main.dart file.
dart
static const _channel = MethodChannel('flutter_upshot_plugin');
UpshotMethodChannel() {
_channel.setMethodCallHandler (_methodCallHandler);
}
Future <dynamic>_methodCallHandler(MethodCall call) async {
if (call.method == 'upshotPushToken ') {
Map data = call.arguments as Map;
}
}
Get Android Push Click Payload Callback via MethodChannel
Add below lines of code in main.dart file.
dart
if (Platform.isAndroid) {
const EventChannel("flutter_upshot_plugin/onPushReceive").receiveBroadcastStream().listen ((data) {
});
const EventChannel("flutter_upshot_plugin/pushClick").receiveBroadcastStream().listen ((data) {
});
}
iOS Integration
For iOS, you need to configure push notifications in your AppDelegate
:
swift
import UIKit
import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
if let controller : FlutterViewController =
UIApplication.shared.keyWindow?.rootViewController as? FlutterViewController {
let upshotChannel = FlutterMethodChannel(name: "flutter_upshot_plugin",
binaryMessenger: controller.binaryMessenger)
DispatchQueue.main.asyncAfter(deadline: .now()) {
upshotChannel.invokeMethod("upshotPushToken", arguments: ["token": token])
let userDefults = UserDefaults.standard
userDefults.set(token, forKey: "upshot_token")
}
}
}
override func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler:
@escaping (UIBackgroundFetchResult) -> Void) {
if let controller : FlutterViewController =
UIApplication.shared.keyWindow?.rootViewController as? FlutterViewController {
let upshotChannel = FlutterMethodChannel(name: "flutter_upshot_plugin",
binaryMessenger: controller.binaryMessenger)
DispatchQueue.main.asyncAfter(deadline: .now()) {
upshotChannel.invokeMethod("upshotPushClickPayload", arguments: userInfo)
}
}
}
iOS Push Click Payload Callback via MethodChannel
dart
import 'package:flutter/services.dart';
class PushNotificationManager {
static const _channel = MethodChannel('flutter_upshot_plugin');
static void initialize() {
_setupMethodChannel();
}
static void _setupMethodChannel() {
_channel.setMethodCallHandler((MethodCall call) async {
switch (call.method) {
case 'onUpshotPushClick'://This will give deeplink callback for push
_handlePushClick(call.arguments);
break;
case 'upshotPushClickPayload'://This will give push complete payload
_handlePushNotification(call.arguments);
break;
}
});
}
static void _handlePushNotification(dynamic arguments) {
Map<String, dynamic> pushData = arguments;
print('📱 Push Notification Received: $pushData');
}
static void _handlePushClick(dynamic arguments) {
Map<String, dynamic> clickData = arguments;
print('👆 Push Notification Clicked: $clickData');
// Handle deep linking or navigation based on push data
}
}
Best Practices
- Permission Timing: Request notification permissions at the right moment in user journey
- Personalization: Use user data to send relevant, personalized notifications
- Timing: Send notifications when users are most likely to engage
- Frequency: Don't overwhelm users with too many notifications
- Deep Linking: Always include deep links to relevant content
- Testing: Test notifications on both iOS and Android devices
- Analytics: Track notification open rates and user engagement
Troubleshooting
Common Issues
Notifications Not Appearing:
- Check if notification permissions are granted
- Verify FCM/APNS tokens are correctly sent to Upshot
- Ensure device is connected to internet
- Check if app is in background/foreground
iOS Specific Issues:
- Verify APNS certificate is uploaded to Upshot dashboard
- Check if push notifications capability is enabled in Xcode
- Ensure provisioning profile supports push notifications
Android Specific Issues:
- Verify FCM service account key is uploaded to Upshot
- Check if Google Services plugin is applied
- Ensure Firebase configuration is correct
Deep Links Not Working:
- Verify deep link URLs are correctly formatted
- Check if app handles deep link routes properly
- Test deep links from both notification and direct URL