首页 > 代码库 > ionic2 jpush

ionic2 jpush

ionic2

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

install

先安装官方的cordova插件

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

在安装本库

$ npm install ionic2-jpush --save

use

import ‘rxjs;
import Component from ‘@angular/core;
import Platform from ‘ionic-angular;
...
import JPushService from ‘ionic2-jpush/dist
 
@Component({
  templateUrl‘plugins-test.html,
  providers  [JPushService]
 
})
export class PluginsTestPage {
  constructor(
    private platformPlatform,
    private jPushPluginJPushService
  {
       let openNotification this.jPushPlugin.openNotification()
         .subscriberes => {
           console.log(res);
           console.log(‘收到点击通知事件)
         })
 
 
       let receiveNotification this.jPushPlugin.receiveNotification()
         .subscriberes => {
           console.log(res)
           console.log(‘收到通知)
         })
 
       let receiveMessage this.jPushPlugin.receiveMessage()
         .subscriberes => {
           console.log(res)
           console.log(‘收到自定义消息)
         })
 
       let backgroundNotification this.jPushPlugin.backgroundNotification()
         .subscriberes => {
           console.log(res)
           console.log(‘收到后台通知)
         })
 
     }
 
    /**
    * 注册极光
    */
   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))
     }
  }
 
}

API

名称参数返回类型描述
init Promise 注册极光
getRegistrationID Promise 获取ID
stopPush Promise 停用推送
resumePush Promise 恢复推送
isPushStopped Promise 推送是否被停用
setTagsWithAlias tags:Array,alias:string Promise 设置tags和alias
setTags tags:Array Promise 设置tags
setAlias alias:string Promise 设置alias
setBadge value:number Promise 设置badge 仅 ios
setApplicationIconBadgeNumber value:number Promise 设置badge 仅 ios
reSetBadge Promise 移除badge 仅 ios
getApplicationIconBadgeNumber Promise 获取badge 仅 ios
clearNotificationById id:number Promise 清除指定ID通知 仅 android
clearAllNotification id:number Promise 清除所有通知 仅 android
openNotification Observable 点击通知事件
receiveNotification Observable 收到通知事件
receiveMessage Observable 收到自定义消息事件
backgroundNotification Observable 后台收到通知事件

Environment

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.5
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.0.0
OS: macOS Sierra
Node Version: v6.9.2
Xcode version: Xcode 8.2.1 Build version 8C1002

ionic2 jpush