1.0.1 • Published 3 years ago

@aks-dev/umeng v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

安装

$ npm install @aks-dev/upush --save

or

$ yarn add @aks-dev/upush

配置

android


  • MainApplication.onCreate()
UMCommonHelper.getInstance().preInit(
        this,
        "6285xxxxxd55d",
        "27b961axxxxxx54cf976");

UMPushHelper.getInstance().preSet(
        this,
        null
);

离线推送配置

  • buildscript.repositories
maven { url 'https://developer.huawei.com/repo/' }
  • buildscript.dependencies
classpath 'com.huawei.agconnect:agcp:1.6.0.300'
  • allprojects.repositories
maven { url 'https://developer.huawei.com/repo/' }
maven { url 'https://repo1.maven.org/maven2/' }
  • agconnect-services.json
  • AndroidManifest.xml
<meta-data
    android:name="com.huawei.hms.client.appid"
    android:value="appid=xxxx" />
<meta-data
    android:name="com.vivo.push.api_key"
    android:value="xxxx" />
<meta-data
    android:name="com.vivo.push.app_id"
    android:value="xxxx" />

ios


#import "UMPushHelper.h"
#import "UMCommonHelper.h"

eg:

  • AppDelegate.application...didFinishLaunchingWithOptions()
[[UMCommonHelper share] setAppKey:@"xxx"];
[[UMPushHelper share] registerForRemoteNotificationsWithLaunchOptions:launchOptions];

other functions ...

//==================push============================================

//iOS10以下使用这两个方法接收通知
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [[UMPushHelper share] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];

}

//iOS10新增:处理前台收到通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    [[UMPushHelper share] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
}

//iOS10新增:处理后台点击通知的代理方法
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler{
    [[UMPushHelper share] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
}

/**
 * 获取deviceToken
 */
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [[UMPushHelper share] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

//==================push============================================

js


  • import * as upush from '@aks-dev/upush'
函数作用
initsdk冷启动,返回deviceToken
addListener监听通知事件
setBadgeCount设置角标

eg:

React.useEffect(() => {
    let subscription = upush.addEventListener((event) => {
        //todo:
    })

    return ()=>{
        subscription.remove()
    }
}, [])