npm install ionic2-jpush

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][downloads-url] [![MIT License][license-image]][license-url]
为ionic2调用极光插件提供符合angular2及TS的调用方式
说在前面:如果想使用 ionic-native 的调用方式,可以参考https://github.com/zjcboy/ionic2-jpush-demo
$ cordova plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey
在安装本库
$ npm install ionic2-jpush --save
``typescript
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 {}
`
`typescript
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)
})
}
}
``
[npm-url]: https://www.npmjs.com/package/ionic2-jpush
[npm-image]: https://img.shields.io/npm/v/ionic2-jpush.svg
[downloads-image]: https://img.shields.io/npm/dm/ionic2-jpush.svg
[downloads-url]: http://badge.fury.io/js/ionic2-jpush
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE