0.0.41 • Published 4 years ago

react-native-rd-package v0.0.41

Weekly downloads
166
License
MIT
Repository
-
Last release
4 years ago

Supported versions

"react": ">=16.8.6"

"react-native": ">=0.60.0"

Installation

  • Install prerequisites.
$ yarn add @react-native-community/async-storage
  • Install package.
$ yarn add react-native-rd-package
  • Install pods (IOS only).
$ cd ios
$ pod install

Platform Integrations

Android

  • Create a Firebase project and register your app. Download google-services.json file and place it in android/app folder.
  • Add below line to your android/build.gradle file's dependencies section.
    classpath 'com.google.gms:google-services:4.3.3'
  • Add below line to your android/app/build.gradle file's bottom.
apply plugin: 'com.google.gms.google-services'

IOS

  • Enable Push Notifications and Background Modes->Remote Notifications capabilities.
  • Import library in AppDelegate.h
#import <UserNotifications/UNUserNotificationCenter.h>
  • Modify AppDelegate.h and add UNUserNotificationCenterDelegate.
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
  • Import libraries in AppDelegate.m
#import "RelatedDigitalPushModule.h"
#import <UserNotifications/UserNotifications.h>
  • Modify AppDelegate.m file's didFinishLaunchingWithOptions method and add the following just before return statement.
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
  • Modify AppDelegate.m and add following methods.
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
 [RelatedDigitalPushModule didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
 [RelatedDigitalPushModule didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RelatedDigitalPushModule didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
 [RelatedDigitalPushModule didFailToRegisterForRemoteNotificationsWithError:error];
}

-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

Usage

import React, { useState, useEffect } from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  Button,
  View,
  ActivityIndicator,
  Platform
} from 'react-native';

import { addEventListener, removeEventListener, requestPermissions, EuroMessageApi, VisilabsApi } from 'react-native-rd-package'

const App = () => {
  const [loading, setLoading] = useState(false)

  const appAlias = 'alias'
  const euroMessageSubscriptionUrl = 'https://pushs.euromsg.com/subscription'
  const euroMessageRetentionUrl = 'https://pushr.euromsg.com/retention'

  const siteId = "SID";
  const organizationId = "OID";
  const segmentUrl = "http://lgr.visilabs.net";
  const realTimeUrl = "http://rt.visilabs.net";
  const dataSource = "datasource";

  const euroMessageApi = new EuroMessageApi(appAlias, euroMessageSubscriptionUrl, euroMessageRetentionUrl)
  const visilabsApi = new VisilabsApi(appAlias, siteId, organizationId, segmentUrl, realTimeUrl, dataSource)

  useEffect(() => {
    addExtra()
    addListeners()

    return () => removeListeners()
  }, [])

  const addListeners = () => {

    addEventListener('register', async (token) => {
      const subscribeResult = await euroMessageApi.subscribe(token)

      visilabsApi.register(token, (result) => {
        
      })
    }, euroMessageApi)

    addEventListener('registrationError', async (registrationError) => {
      console.log('registrationError is ', registrationError)
    }, euroMessageApi)
  }

  const addExtra = async () => {
    await euroMessageApi.setUserProperty('extra', 1)
  }

  const removeListeners = () => {
    removeEventListener('register')
    removeEventListener('registrationError')
  }

  return (
    <>
      <SafeAreaView>
        {
          loading ?
          <ActivityIndicator 
            size='large'
            animating={loading} /> :
          <ScrollView
            contentInsetAdjustmentBehavior="automatic"
            style={styles.scrollView}>
            <Button 
              title='REQUEST PERMISSONS'
              onPress={() => {
                requestPermissions()
              }} 
            />
          </ScrollView>
        }
      </SafeAreaView>
    </>
  );
};

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: '#FFF',
    padding: 20
  },
  divider: {
    height: 20
  }
});

export default App;
0.0.40

4 years ago

0.0.41

4 years ago

0.0.39

4 years ago

0.0.37

4 years ago

0.0.38

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.30

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.29

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago