GuidesDiscussions
Log In
Guides

Initializing the SDK

SDK Invocation and Functions

Initialize the DR SDK in main.dart by creating an instance of drplugin:

import 'package:drplugin/drplugin.dart';

final _drpluginPlugin = Drplugin();

To invoke the DR SDK, call the following method:

_drpluginPlugin.launch();

Custom Org Selection (Optional):

If the client wishes to make the same app available for different organizations, they can achieve this by calling the following API to the DR SDK.

await _drpluginPlugin.sendHostAppCountryCode(cc);

Opt-In/Opt-Out Settings:

Monetization Opt-In / Opt-Out:

To update Opt-In status:

_drpluginPlugin.updateOptInStatus(value);

To get Opt-in status:

bool? optin = await _drpluginPlugin.getOptInStatus();

Engagement Opt-In/Opt-Out:

To update Opt-In status:

_drpluginPlugin.updateEngagementOptInStatus(value);

To get Opt-in status:

bool? optin = await _drpluginPlugin.getEngagementOptInStatus();

Example for sending events:

void sendEvent() {   
  Map<String, dynamic> parameters = new Map();  
  parameters["EVENT_NAME"] = "CustomEvent";  
  _drpluginPlugin.trackInAppEvents(parameters);  
}

Push Notifications

Android

FCM Integration in Android:

Create the methods for firebase:

@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  // If you're going to use other Firebase services in the background, such as Firestore,
  // make sure you call `initializeApp` before using other Firebase services.
  await Firebase.initializeApp();
  Map<String, dynamic> parameters = Map();

  parameters["data"] = message.data;
  parameters["from"] = message.from;

  if (Platform.isAndroid) {
    _drpluginPlugin.invokeFCM(parameters);
  }
  print('Handling a background message ${message.messageId}');
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  runApp(const MyApp());
}

void listenFCM() async {
  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    Map<String, dynamic> parameters = Map();
    parameters["data"] = message.data;
    parameters["from"] = message.from;

    if (Platform.isAndroid) {
      _drpluginPlugin.invokeFCM(parameters);
    }
  });
}

void getToken() async {
  await FirebaseMessaging.instance.getToken().then((token) {
    setState(() {
      _drpluginPlugin.refreshToken();
    });
  });
}

iOS

Request Push Notification Permission:

void requestNotifications() {  
  _drpluginPlugin.requestPushPermission();  
}  

App Tracking Permission:

DR SDK needs to request App Tracking permission from the user to collect IDFA details and track user activity on DR Platform. Below is the sample code to invoke the same from any View Controller class.

void requestAppTracking() {  
  _drpluginPlugin.requestAppTracking();  
}  

In case you have another push SDK or an implementation of your own, you might want to turn off DR SDK's method swizzling. DR SDK performs method swizzling on top of iOS' APNS delegate methods to capture relevant events from notifications and analytics. This means that when our SDK is present, it overrides whatever other APNS implementation already present in the app.

Disable Method Swizzling:
[Add this section to the web documentation: https://developers.digitalreef.com/docs/push-notifications#disable-method-swizzling]

Add APNS methods to your AppDelegate:
[Add this section to the web documentation

: https://developers.digitalreef.com/docs/push-notifications#add-apns-methods-to-your-appdelegate]