# react-native-rd-package

> react-native-rd-package

Latest version **0.0.41** (published 2020-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-rd-package
pnpm add react-native-rd-package
yarn add react-native-rd-package
bun add react-native-rd-package
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.41 |
| Published | 2020-06-22 |
| First published | 2020-06-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 145.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Pragmasoft |
| Maintainers | pragmasoft |

## Links

- npm: https://www.npmjs.com/package/react-native-rd-package
- Homepage: https://bitbucket.org/AhmetKiziltan/related-push-sdk
- npm.io page: https://npm.io/package/react-native-rd-package

## Dependencies (1)

- [querystring](https://npm.io/package/querystring.md) ^0.2.0

## Recent versions

- 0.0.41 (latest) — 2020-06-22
- 0.0.40 — 2020-06-22
- 0.0.39 — 2020-06-22
- 0.0.38 — 2020-06-18
- 0.0.37 — 2020-06-18
- 0.0.36 — 2020-06-18
- 0.0.35 — 2020-06-18
- 0.0.34 — 2020-06-16
- 0.0.33 — 2020-06-16
- 0.0.32 — 2020-06-16
- 0.0.31 — 2020-06-16
- 0.0.30 — 2020-06-16
- 0.0.29 — 2020-06-16
- 0.0.28 — 2020-06-16
- 0.0.27 — 2020-06-16
- … 26 more at https://npm.io/package/react-native-rd-package/versions

## README

## 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.
   ```gradle
   classpath 'com.google.gms:google-services:4.3.3'
   ```
* Add below line to your `android/app/build.gradle` file's bottom.
```gradle
apply plugin: 'com.google.gms.google-services'
```

### IOS
* Enable **Push Notifications** and **Background Modes->Remote Notifications** capabilities.
* Import library in `AppDelegate.h`
```objective-c
#import <UserNotifications/UNUserNotificationCenter.h>
```
* Modify `AppDelegate.h` and add UNUserNotificationCenterDelegate.
```objective-c
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>
```
* Import libraries in `AppDelegate.m`

```objective-c
#import "RelatedDigitalPushModule.h"
#import <UserNotifications/UserNotifications.h>
```

* Modify `AppDelegate.m` file's `didFinishLaunchingWithOptions` method and add the following just before return statement.
```objective-c
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
```
* Modify `AppDelegate.m` and add following methods.
```objective-c
- (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
```jsx
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;

```

---
_Source: https://npm.io/package/react-native-rd-package · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
