npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-jpush-capacitor

v3.7.9

Published

JPush for Capacitor plugin

Downloads

32

Readme

cordova-plugin-jpush-capacitor

platforms weibo

在官方基础上,增加对Capacitor电容器的支持(支持Capacitor3)

Capacitor(2.0/3.0) 安装

npm install cordova-plugin-jpush-capacitor -S

npm install cordova-plugin-device -S

npm install cordova-plugin-jcore -S

同步插件至Native项目:

npx cap sync

IOS 使用

配置JPUSH APPkey: https://img-blog.csdnimg.cn/2020110211285992.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3podXhpYW5kYW4=,size_16,color_FFFFFF,t_70#pic_center 也可以在安装npm包之后,在插件目录 node_modules/cordova-plugin-jpush-capacitor/src/ios/JPushConfig.plist 中修改,推荐使用这个方式更改,更改之后需要手动在执行一遍npx cap sync

IOS项目中添加桥接头文件, 如图: https://img-blog.csdnimg.cn/20201102105208957.gif#pic_center 生成的.m文件可以删除

在生成的头文件中导入jpush:

#import "JPUSHService.h"

Capacitor 注册极光devicetoken

Capacitor2.0版本: 在Appdelegate.swift 文件的 didRegisterForRemoteNotificationsWithDeviceToken 方法中添加如下代码:

func application(application: UIApplication,
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
  NSNotificationCenter.defaultCenter().postNotificationName("DidRegisterRemoteNotification", object: deviceToken)
  JPUSHService.registerDeviceToken(deviceToken)
}

Capacitor3.0版本: 在Appdelegate.swift中加入以下代码:

func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  JPUSHService.registerDeviceToken(deviceToken)
}

以上准备就绪后,需要手动调用初始化SDK:

window.JPush.startJPushSDK() // 可以打印一下window.JPush, 官方支持的API均可以使用

Android 使用

配置JPUSH APPkey: Android 配置APPKey 也可以在安装npm包之后,在插件目录 node_modules/cordova-plugin-jpush-capacitor/plugin.xml 中修改,推荐使用这个方式更改

// 在plugin.xml中将此处的$APP_KEY替换成自己的即可
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" /> 

替换之后需要手动在执行一遍npx cap sync,直接在原生项目中做替换的可不必运行

Android无需手动初始化SDK

示例代码(以Ionic为例)

import { isPlatform } from '@ionic/vue';
class Jpush {
    jpush: any;

    constructor() {
        if (window.JPush) {
            this.jpush = window.JPush;
            this.jpush.setDebugMode(true);
            if (isPlatform('ios')) {
                this.jpush.startJPushSDK();
            }
            this.jpush.init();
        }
    }

    getRegistrationID() {
        return new Promise(resolve => {
            this.jpush.getRegistrationID(function (rId: string) {
                resolve(rId);
                console.log("JPushPlugin:registrationID is " + rId);
            })
        })
    }

    // 设置别名
    setAlias(alias: string) {
      return new Promise(((resolve, reject) => {
        this.jpush.setAlias({
          alias,
          sequence: new Date().valueOf(),
        },  (res: { alias: string, sequence: number }) => {
          console.log('别名设置成功: ', res);
          resolve(res);
        },  (err: { code: number, sequence: number }) => {
            console.log('别名设置失败: ', err);
            setTimeout(() => this.setAlias(alias), 3000);
            reject(err);
        })
      }))

    }

    // 设置角标 只限IOS
    setBadge(badge: number) {
      if (isPlatform('ios')) {
        this.jpush.setBadge(badge);
      }
    }
}
export default Jpush

API请查阅官方文档:https://github.com/jpush/jpush-phonegap-plugin