Skip to content

Usage

The applicationId is your application's id, from its settings page in the dashboard (Getting started). The SDK talks to PlingBuddy's production service unless the configuration names another baseUrl (see Staging).

Dart
import 'package:plingbuddy/plingbuddy.dart';

final plingBuddy = PlingBuddy();

// At startup. The SDK remembers the user, so a launch without one keeps it;
// a device without a user belongs to an anonymous recipient.
await plingBuddy.initialize(const Configuration(applicationId: '<your application id>'));

// When the app wants to offer notifications. Returns whether they're allowed.
final allowed = await plingBuddy.askForPermission(
  // Optional texts for the dialog shown when notifications were turned off before.
  settingsPrompt: const SettingsPrompt(
    title: 'Notifications are off',
    message: 'Open Settings to turn them on.',
    openButton: 'Open Settings',
    cancelButton: 'Not now',
  ),
);
  • permissionStatus() reads the permission without prompting: granted, provisional (iOS), denied or notDetermined.
  • pushToken() answers the push token while notifications are allowed, otherwise null.
  • initialize can be called again to apply a new configuration. Each call replaces the whole configuration, so pass every setting again, baseUrl included: a configuration without it goes to production, which starts a new installation there.

Staging

To try your app against PlingBuddy's staging service, with the applicationId of your application there, pass its URL:

Dart
await plingBuddy.initialize(const Configuration(
  applicationId: '<your staging application id>',
  baseUrl: PlingBuddy.stagingUrl, // https://staging.plingbuddy.com/
));

Switching between staging and production starts a new installation for the other service.

Notifications while the app is open

Dart
await plingBuddy.initialize(const Configuration(
  applicationId: '<your application id>',
  showNotificationsInForeground: true,
));

Without it, each platform keeps its default: Android shows the service's notifications while the app is open, iOS hides them. true or false makes both behave the same. A hidden notification is reported to the service as suppressed.

Cleaning up

The SDK is one per process; every PlingBuddy instance talks to it. dispose() stops receiving its errors and identity token requests until the next call. The SDK itself keeps running.