- ortto_flutter_sdk_platform_interface https://pub.dev/packages/ortto_flutter_sdk_platform_interface
- ortto_flutter_sdk_android https://pub.dev/packages/ortto_flutter_sdk_android
- ortto_flutter_sdk_ios https://pub.dev/packages/ortto_flutter_sdk_ios
- Set up and configure firebase flutter project
- Install Flutterfire CLI
dart pub global activate flutterfire_cli
- Attach Firebase project
flutterfire configure --project=<FIREBASE_PROJECT_ID>
- Add Firebase messaging dependency
flutter pub add firebase_messaging
- Ensure
lib/firebase_options.dart
config file is present and configured correctly
- In the root of your project, run:
flutter pub add ortto_flutter_sdk
- In your projects main file, import firebase_messaging
import 'package:firebase_messaging/firebase_messaging.dart';
- Import firebase_options file
import 'firebase_options.dart';
- Import ortto_flutter_sdk
import 'package:ortto_flutter_sdk/ortto_flutter_sdk.dart';
- Set up Firebase Messaging and Ortto
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await Ortto.instance.init(
appKey: '<APP_KEY>',
endpoint: '<APP_ENDPOINT>',
);
await Ortto.instance.initCapture(
dataSourceKey: '<DATASOURCE_KEY>',
captureJsUrl: '<CAPTURE_JS_URL>',
apiHost: '<API_HOST>>',
);
const uuid = Uuid();
final user = UserID(
externalId: uuid.v4(),
email: 'example@ortto.com',
);
await Ortto.instance.identify(user);
await Ortto.instance.dispatchPushRequest();
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(badge: true, alert: true, sound: true);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (message.notification != null) {
Ortto.instance
.onbackgroundMessageReceived(message.toMap())
.then((handled) {
print("handled $handled");
return handled;
});
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(const MyApp());
}
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Ortto.instance
.onbackgroundMessageReceived(message.toMap())
.then((handled) {
return handled;
});
}
- Open the
ios/Runner.xcworkspace
workspace folder in Xcode - Add a new capability for Background Modes
- Select your project in the Project Navigator
- Navigate to the Runner target -> Signing & Capabilities
- Click the + Capability button
- Select Background Modes
- Check the Remote notifications checkbox
- Add a background extension
- In the application menu bar select File -> New -> Target
- Select Notification Service Extension
- Click Next
- Name the extension
NotificationService
- Click Finish
- In the
ios/Podfile
add the following
target 'NotificationExtension' do
use_frameworks!
pod 'OrttoPushMessagingFCM', '~> 1.5'
end
- Run
pod install --repo-update --project-directory=ios
in root project folder - Open the
NotificationService.swift
file in the NotificationExtension folder - Add an/or replace contents as follows:
import UserNotifications
import OrttoPushMessagingFCM
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
let handled = PushMessaging.shared.didReceive(request, withContentHandler: contentHandler)
}
override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
Please refer to the following documentation for deep linking in Flutter https://docs.flutter.dev/ui/navigation/deep-linking
Ensure your deep linking URL scheme is set up correctly in your Ortto dashboard.
await Ortto.instance.trackLinkClick("deep://link-from/push-notification?with=parameters&included=true");
initialize initializeCapture identify clearData dispatchPushRequest requestPermissions trackLinkClick queueWidget showWidget processNextWidgetFromQueue onMessageReceived
Please report all issues to Github https://github.com/autopilot3/ortto-flutter-sdk/issues
Publishing must be done in this order. Don't forget to update the changelog of each library
# Update version in pubspec.yaml
# Update CHANGELOG.md
cd ortto_flutter_sdk_platform_interface
flutter pub publish
# confirm version and publish
# Update version in pubspec.yaml
# Update CHANGELOG.md
cd ortto_flutter_sdk_ios
flutter pub publish
# confirm version and publish
# Update version in pubspec.yaml
# Update CHANGELOG.md
cd ortto_flutter_sdk_android
flutter pub publish
# confirm version and publish
# Update version in pubspec.yaml
# Update CHANGELOG.md
cd ortto_flutter_sdk
flutter pub publish
# confirm version and publish
MIT License (MIT)