npm package: @opendt/react-native-ali-push
Description: react-native wrapper of Ali Push SDK, support both iOS and Android.
Author: Yeo Yang
Latest version: 1.0.0

# React Native Ali Push
react-native wrapper of Ali Push SDK, support both iOS and Android.

Note, this library only support react-native 0.60+

## Installation
Install library via npm:
```bash
npm install --save @opendt/react-native-ali-push
```

## Additional steps
* Android
1. add aliyun maven repository to project's `build.gradle` file:
   ```diff
      allprojects {
          repositories {
   +          maven {
   +              // Aliyun repositories
   +              url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
   +          }
          }
      }
   ```
1. specify your `appKey` and `appSecret` in `AndroidManifest.xml`:
   ```diff
      <application android:name="*****">
   +    <meta-data android:name="com.alibaba.app.appkey" android:value="PUSH_APP_KEY"/>
   +    <meta-data android:name="com.alibaba.app.appsecret" android:value="PUSH_APP_SECRET"/>
      </application>
   ```
1. update your `MainApplication.java` file:
   ```diff
   +  import xin.dayukeji.rn.alipush.DTAliPushManager;
   
      public class MainApplication extends Application implements ReactApplication {
          @Override
          public void onCreate() {
              super.onCreate();
              SoLoader.init(this, /* native exopackage */ false);
   +          DTAliPushManager.initCloudChannel(this);
          }
       }
   ```
1. update your `MainActivity.java` file(or wherever you create an instance of ReactActivityDelegate):
   ```diff
   +  import xin.dayukeji.rn.alipush.DTAliPushManager;
   
      public class MainActivity extends ReactActivity {
   +      @Override
   +      protected ReactActivityDelegate createReactActivityDelegate() {
   +          return new ReactActivityDelegate(this, getMainComponentName()) {
   +              @Override
   +                  protected Bundle getLaunchOptions() {
   +                      Bundle initialProps = new Bundle();
   +                      initialProps.putBundle("notification", DTAliPushManager.extractPushData(getIntent()));
   +                      return initialProps;
   +                  }
   +              };
   +          }
   +      }
      }
   ```

* iOS
1. add Aliyun's Pod repository to your `Podfile`:
   ```
   source 'https://github.com/aliyun/aliyun-specs.git'
   ```
   or, you can add global repo, run:
   ```bash
   pod repo add aliyum https://github.com/aliyun/aliyun-specs.git master
   ```
   then you need to complete the linking on iOS, run:
   ```bash
   cd ios && pod install
   ```
1. update your `AppDelegate.m` file:
   ```diff
   +  #import "DTAliPush.h"
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // ...
   +    [[DTAliPush sharedInstance] initWithKey:@"PUSH_APP_KEY" appSecret:@"PUSH_APP_SECRET" callback:nil];
   +    [[DTAliPush sharedInstance] registerAPNS:application];
   +    [[DTAliPush sharedInstance] handleNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
        return YES;
      }
   
   +  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
   +    [[DTAliPush sharedInstance] registerDeviceToken:deviceToken withCallback:nil];
   +  }
   
   +  // for iOS < 10
   +  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
   +    [[DTAliPush sharedInstance] handleNotification:userInfo];
   +  }
   ```
1. enable `Push Notifications` capability in Xcode, and config push certifications in Aliyun Console,
see [help doc](https://help.aliyun.com/document_detail/30071.html)

## Usage
1. import package in your js files
   ```js
   import AliPush from '@opendt/react-native-ali-push';
   ```

1. `AliPush.subscribe(event: string, callback: Function)`  
subscribe to SDK event. available event are:
   ```javascript
   AliPush.subscribe(AliPush.EVT_NOTIFICATION, notification => {
       console.log('new notification', notification);
   });
   ```
   - AliPush.EVT_NOTIFICATION: event indicated that new notification received.
   - AliPush.EVT_NOTIFICATION_OPENED: user click the notification to open it.
   - AliPush.EVT_NOTIFICATION_REMOVE: user dismissed the notification.

1. `AliPush.bindAccount(uid: string): Promise`  
bind account to Ali Push service

1. `AliPush.unbindAccount(uid: string): Promise`  
unbind account, if you want to bind to another account, you can directly call `bindAccount(anotherUid)`.

1. `AliPush.binfTag(tags: Array<string>, target, alias: string): Promise`  
bind tags to specified target, where `target` must be one of `TARGET_ACCOUNT`, `TARGET_DEVICE`, `TARGET_ALIAS`.
if target is `TARGET_ALIAS`, third param `alias` must be specified.

1. `AliPush.unbindTag(tags: Array<string>, target, alias: string): Promise`  
unbind tags from specified target.