Skip to content

Repository files navigation

ionic2-JPush

Dependency StatusNPM versionDownloadsMIT 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'})exportclassPluginsTestPage{constructor(privateplatform: Platform,privatejPushPlugin: 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))}}}

API

名称参数返回类型描述
initPromise注册极光
getRegistrationIDPromise获取ID
stopPushPromise停用推送
resumePushPromise恢复推送
isPushStoppedPromise推送是否被停用
setTagsWithAliastags:Array,alias:stringPromise设置tags和alias
setTagstags:ArrayPromise设置tags
setAliasalias:stringPromise设置alias
setBadgevalue:numberPromise设置badge 仅 ios
setApplicationIconBadgeNumbervalue:numberPromise设置badge 仅 ios
reSetBadgePromise移除badge 仅 ios
getApplicationIconBadgeNumberPromise获取badge 仅 ios
clearNotificationByIdid:numberPromise清除指定ID通知 仅 android
clearAllNotificationid:numberPromise清除所有通知 仅 android
openNotificationObservable点击通知事件
receiveNotificationObservable收到通知事件
receiveMessageObservable收到自定义消息事件
backgroundNotificationObservable后台收到通知事件

About

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

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages