Skip to main content

Notify

Set up and Initialize SDK#

The Flybuy SDK must be initialized when the application starts in order to configure the app authorization token and handle appropriate lifecycle methods.

Important: Complete all steps in the Android and iOS setup guides. Key steps are highlighted below.

  1. Install SDK
  2. Post-install Steps for iOS and Android
  3. Initialize SDK on launch

Create for Sites in Region#

Call this method to create a notification for a list of sites in a given circular region (latitude, longitude, and radius). This will clear any previously set notifications and create a new notification for the region.

Params#

NameTypeExample
regionCircularRegion{ latitude: 47.6234207, longitude: -122.3300605, radius: 100 }
notificationNotificationInfo{ title: 'Test Notification', message: 'Test Notification message', data: { key1: 'value1', key2: 'value2' }}

Example#

const region = {
latitude: 47.6234207,
longitude: -122.3300605,
radius: 100,
};
const notification = {
title: 'Test Notification',
message: 'Test Notification message',
data: {
key1: 'value',
key2: 'value',
},
};
FlyBuy.Notify.createForSitesInRegion(region, notification);

Clear Notifications#

Clear all geofence notifications.

Params#

NameType
NoneNone

Example#

FlyBuy.Notify.clearNotifications();

Create for Sites#

Create geofence notification for list of sites.

Params#

NameTypeExample
notificationNotificationInfo{ title: 'Test Notification', message: 'Test Notification message', data: { key1: 'value', key2: 'value' }}
sites[Site][{},...]

Example#

const notification = {
title: 'Test Notification',
message: 'Test Notification message',
data: {
key1: 'value',
key2: 'value',
},
};
const sites = [
{
id: 15942,
name: 'Test Site',
phone: '333-333-3333',
streetAddress: null,
fullAddress: '500 Yale Ave N, Seattle, WA 98109, USA',
locality: null,
region: null,
country: null,
postalCode: null,
latitude: '47.6234207',
longitude: '-122.3300605',
coverPhotoUrl: null,
iconUrl: null,
instructions: '',
description: '',
partnerIdentifier: '001',
},
];
FlyBuy.Notify.createForSites(sites, notification);

Sync Notify Campaign Data#

Notify sync method is provided as a development tool, in production applications it should not be called. The SDK will automatically sync data with the Flybuy portal. However the schedule used by the SDK may not be conducive to testing and development iterations.

Params#

NameTypeExample
forceBooleantrue

Example#

FlyBuy.Notify.sync(true);

Background Data Refresh (iOS only)#

Notify Campaigns require the background fetch capability to be enabled in the target settings. An old rock in the desert

After that, you can follow this steps:

  1. Modify your AppDelegate.h

    #import <React/RCTBridgeDelegate.h>
    #import <UIKit/UIKit.h>
    #import <UserNotifications/UserNotifications.h> // <-- add this
    // Add UNUserNotificationCenterDelegate
    @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
    ....
    @end
  2. Modify your AppDelegate.m

    #import "AppDelegate.h"
    ... other imports
    #import <react-native-bildit-flybuy/Flybuy-Bridging-Header.h> // <-- add this line
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    ...
    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
    moduleName:@"FlybuyExample"
    initialProperties:nil];
    // ------ Add this block
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    center.delegate = self;
    // ------
    ...
    return YES;
    }
    // ----- Add this block
    - (void)application:(UIApplication *)application
    performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
    [[Flybuy shared] performFetchWithCompletionHandler:completionHandler];
    }
    // ------

Handle Notification Response#

Configuration#

iOS#

Modify your AppDelegate.m

Please make sure to import #import <react-native-bildit-flybuy/Flybuy-Bridging-Header.h> and make this changes.

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
[[Flybuy shared] handleNotificationResponse:response];
}
// Enables app to receive notifications while in the foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
info

Please make sure to request notification permission on your app to properly receive any local notification from FlyBuy.

Android#

No changes needed.

Usage#

Set up event listeners to get updates about notification metadata.

React.useEffect(() => {
const notifyEventListener = FlyBuy.eventEmitter.addListener(
'notifyEvents',
(event) => {
console.log('notify event', event);
}
);
return () => {
notifyEventListener.remove();
};
}, []);