@opendt/react-native-ali-push

1.0.0 • Public • Published

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:

npm install --save @opendt/react-native-ali-push

Additional steps

  • Android
  1. add aliyun maven repository to project's build.gradle file:
       allprojects {
           repositories {
    +          maven {
    +              // Aliyun repositories
    +              url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
    +          }
           }
       }
  2. specify your appKey and appSecret in AndroidManifest.xml:
       <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>
  3. update your MainApplication.java file:
    +  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);
           }
        }
  4. update your MainActivity.java file(or wherever you create an instance of ReactActivityDelegate):
    +  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:
    pod repo add aliyum https://github.com/aliyun/aliyun-specs.git master
    then you need to complete the linking on iOS, run:
    cd ios && pod install
  2. update your AppDelegate.m file:
    +  #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];
    +  }
  3. enable Push Notifications capability in Xcode, and config push certifications in Aliyun Console, see help doc

Usage

  1. import package in your js files

    import AliPush from '@opendt/react-native-ali-push';
  2. AliPush.subscribe(event: string, callback: Function)
    subscribe to SDK event. available event are:

    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.
  3. AliPush.bindAccount(uid: string): Promise
    bind account to Ali Push service

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

  5. 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.

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0

Package Sidebar

Install

npm i @opendt/react-native-ali-push

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

46 kB

Total Files

15

Last publish

Collaborators

  • wangxinyu1
  • yeoyang