ij
ionic2-jpush
npm i ionic2-jpush
ij

ionic2-jpush

ionic2激光推送的封装基于 jpush-phonegap-plugin

by Hsuan Lee

0.1.1 (see all)License:MITTypeScript:Built-In
npm i ionic2-jpush
Readme

ionic2-JPush

Dependency Status NPM version Downloads MIT License

为ionic2调用极光插件提供符合angular2及TS的调用方式

说在前面:如果想使用 ionic-native 的调用方式,可以参考https://github.com/zjcboy/ionic2-jpush-demo

install

先安装官方的cordova插件 https://github.com/jpush/jpush-phonegap-plugin.git

$ cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey

在安装本库

$ npm install ionic2-jpush --save

Import module

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
...
import { IonJPushModule } from 'ionic2-jpush'

@NgModule({
  declarations: [
    MyApp,
    ...
  ],
  imports: [
    IonJPushModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    ...
  ],
  providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}]
})
export class AppModule {}

Use

import 'rxjs';
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
...
import { JPushService } from 'ionic2-jpush'

@Component({
  templateUrl: 'plugins-test.html'

})
export class PluginsTestPage {
  constructor(
    private platform: Platform,
    private jPushPlugin: JPushService
  ) {

        platform.ready().then( () =>{
       
             this.jPushPlugin.openNotification()
               .subscribe( res => {
                 console.log('收到推送');
                 console.log(res)
               });
       
             this.jPushPlugin.receiveNotification()
               .subscribe( res => {
                 console.log('收到推送');
                 console.log(res)
               });
       
             this.jPushPlugin.receiveMessage()
               .subscribe( res => {
                 console.log('收到推送');
                 console.log(res)
               });
       
           })

     }

    /**
    * 注册极光
    */
   init() {
    this.jPushPlugin.init()
    .then(res => alert(res))
    .catch(err => alert(err))
    }

    /**
    * 获取ID
    */
    getRegistrationID() {
     this.jPushPlugin.getRegistrationID()
     .then(res => alert(res))
     .catch(err => alert(err))
     }
     
    /**
    * 设置标签
    */
    setTags() {
    this.jPushPlugin.setTags({
      sequence: Date.now(),
      tags: ['tag1', 'tag2']
    })
    .then((res:any) => {
      console.log(res.tags.toString())
    })
    .catch(err => {
      alert(err);
      console.log(err)
    })
    }
    
  }

API

名称参数返回类型描述
setDebugModebooleanPromise设置 debug 模式
initPromise注册极光
getRegistrationIDPromise获取ID
stopPushPromise停用推送
resumePushPromise恢复推送
isPushStoppedPromise推送是否被停用
setTags{ sequence: number; tags: string[] }Promise设置 tags
addTags{ sequence: number; tags: string[] }Promise添加 tags
deleteTags{ sequence: number; tags: string[] }Promise删除 tags
cleanTags{ sequence: number }Promise清除tags
getAllTags{ sequence: number }Promise获取所有本机设置的 tags
setAlias{ sequence: number; alias: string }Promise设置 alias
deleteAlias{ sequence: number }Promise删除 alias
getAlias{ sequence: number }Promise获取本机设置的 alias

IOS API

名称参数返回类型描述
setBadgevalue:numberPromise设置 badge 至 JPush 服务器
reSetBadgePromise移除 JPush 服务器 badge
getApplicationIconBadgeNumberPromise获取本地 badge
setApplicationIconBadgeNumbervalue:numberPromise设置本地 badge
clearAllLocalNotificationsPromise清除所有本地推送对象

Android API

名称参数返回类型描述
clearNotificationByIdid:numberPromise清除指定ID通知
clearAllNotificationPromise清除所有通知
setPushTimedays: number , startHour: number, endHour: numberPromise设置允许推送时间
setSilenceTimedays: number , startHour: number, endHour: numberPromise设置通知静默时间

可订阅事件

名称参数返回类型描述
openNotificationObservable点击通知事件
receiveNotificationObservable收到通知事件
receiveMessageObservable收到自定义消息事件
backgroundNotificationObservable后台收到通知事件

Downloads/wk

18

GitHub Stars

52

LAST COMMIT

5yrs ago

MAINTAINERS

1

CONTRIBUTORS

0

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
0.1.1
latest
5yrs ago
0.1.0-beta.2
beta
5yrs ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate