repro_flutter 3.12.1 repro_flutter: ^3.12.1 copied to clipboard
A plugin for using the Repro Android/iOS SDK in your Flutter app.
Repro Flutter Plugin #
- Repro plugin for Flutter.
- Support all the features of Repro except for WebView event tracking.
How to add Repro Flutter Plugin to your app #
Add Repro Flutter Plugin #
1. Add dependencies
Add repro_flutter
to your pubspec.yaml
and run flutter packages get
:
dependencies:
flutter:
sdk: flutter
...
repro_flutter: ^3.12.1 # add this line
2. Install the native library (Android)
Add dependencies to android/app/build.gradle
:
dependencies {
implementation 'io.repro:repro-android-sdk:5.17.1' // add this line
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
3. Install the native library (iOS)
Run the following command in the root directory of your app.
$ cd ios
$ pod install
4. Add native code (Android)
Add a custom Application
class extending from io.flutter.app.FlutterApplication
. If you've done this before for the other reasons, please skip this step and just add the call to Repro.setup
(in below).
Create a new Application
class under android/app/src/main/your/package/name
:
package your.package.name;
import io.flutter.app.FlutterApplication;
import io.repro.android.Repro;
public class MyApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
}
}
Set it to android/app/src/main/AndroidManifest.xml
:
<application
- android:name="io.flutter.app.FlutterApplication"
+ android:name="your.package.name.MyApplication"
android:label="repro_integration_test"
android:icon="@mipmap/ic_launcher">
Call Repro.setup
in your Application
class (replace YOUR SDK TOKEN
by your SDK token):
public void onCreate() {
super.onCreate();
Repro.setup(this, "YOUR SDK TOKEN"); // add this line
}
5. Add native code (iOS)
Call Repro#setup
in ios/Runner/AppDelegate.m
(replace YOUR SDK TOKEN
by your SDK token):
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
[Repro setup:@"YOUR SDK TOKEN"]; // add this line
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Enable Push Notifications #
To enable push notifications, you need to add the same implementation of the Android/iOS version of the Repro SDK.
Setup for Android
Note: If you want to use the FlutterFire CLI, the installation process is different. See https://firebase.flutter.dev/docs/overview for more information.
1. Add Firebase Flutter Plugin
Add firebase_core
and firebase_messaging
to your pubspec.yaml
and run flutter packages get
:
dependencies:
flutter:
sdk: flutter
firebase_core: ^1.14.1 # Add this line
firebase_messaging: ^11.2.13 # Add this line
Add google-services.json
into your project.
Please see the official document of Firebase for more information.
2. Add implementation
Please refer to the following document of Repro:
Note: For the Flutter app, you don't need to add firebase_core
and firebase_messaging
statements into app/build.gradle
.
3. Add Firebase initialization code
Add the following code to main.dart
void main() async {
// Initialize FlutterFire
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// Detects that the Firebase token has changed and sends the token to Repro.
FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.onTokenRefresh.listen((token) async {
await Repro.setPushRegistrationID(token);
});
runApp(MyApp());
}
Setup for iOS
Please refer to the following document of Repro:
Development Guide #
Please see the example code in example/lib/main.dart
while refer to the Development Guide of Repro.
How to run the example app #
Replace the following YOUR SDK TOKEN
by your SDK token (if you don't have a Repro account, sign-up here for free).
android/app/src/main/java/io/repro/repro_flutter_example/MyApplication.java
:
public class MyApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
Repro.setup(this, "YOUR SDK TOKEN");
ios/Runner/AppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
[Repro setup:@"YOUR SDK TOKEN"];
Go to example
directory and run:
flutter run
Enable Push Notifications in the example app #
1. Add Firebase Flutter Plugin (for Android)
Uncomment the following code which implements Push Notifications:
pubspec.yaml
:
dependencies:
flutter:
sdk: flutter
# To enable push notifications on Repro, uncomment the following:
# firebase_core: ^1.14.1
# firebase_messaging: ^11.2.13
android/build.gradle
:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// To enable push notifications on Repro, uncomment the following:
// classpath 'com.google.gms:google-services:4.3.10'
}
android/app/build.gradle
:
// To enable push notifications on Repro, uncomment the following:
// apply plugin: 'com.google.gms.google-services'
Add google-services.json
into your project.
Please see the official document of Firebase for more information.
2. Setup APNs Certificate and FCM
Please refer to the following document of Repro:
3. Uncomment code related to Push Notifications
Uncomment the following code which implements Push Notifications:
lib/main.dart
:
void main() async {
// Initialize FlutterFire
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// Detects that the Firebase token has changed and sends the token to Repro.
FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.onTokenRefresh.listen((token) async {
await Repro.setPushRegistrationID(token);
});
runApp(MyApp());
}
android/app/src/main/AndroidManifest.xml
:
<!-- To enable push notifications on Repro, uncomment the following: -->
<receiver
android:name="io.repro.android.ReproReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="io.repro.repro_flutter_example" />
</intent-filter>
</receiver>
<meta-data
android:name="io.repro.android.PushNotification.ChannelId"
android:value="io.repro.flutter.repro_test.channel_id">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ChannelName"
android:resource="@string/repro_channel_name">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ChannelDescription"
android:resource="@string/repro_channel_description">
</meta-data>
<meta-data
android:name="io.repro.android.PushNotification.ShowBadge"
android:value="true">
</meta-data>
android/app/src/main/res/values/strings.xml
:
<!-- To enable push notifications on Repro, uncomment the following: -->
<string name="repro_channel_name">Channel Name</string>
<string name="repro_channel_description">Channel Description</string>
android/app/src/main/java/io/repro/repro_flutter_example/MyApplication.java
:
public void onCreate() {
super.onCreate();
Repro.setup(this, "YOUR SDK TOKEN");
// To enable push notifications on Repro, uncomment the following:
Repro.enablePushNotification();
ios/Runner/AppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
// To enable push notifications on Repro, uncomment the following:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
}];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
...
}
// To enable push notifications on Repro, uncomment the following:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[Repro setPushDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"Remote Notification Error: %@", error);
}
4. Send Push Notifications from Repro
Please see the Dashboard Guide of Repro.
NOTE (for iOS)
Because you may not be able to create the same bundle id for testing, remember to change the bundle id io.repro.reproFlutterExample
to one you have control of.