如何使用
- 安装官方Cordova插件
ionic plugin add jpush-phonegap-plugin --variable APP_KEY=your_jpush_appkey
- 安装模块
ionic3-jpush
npm i ionic3-jpush -S
- 在
app.module.ts
中引入,并加入到@NgModule
的providers
中
import { JPush } from 'ionic3-jpush';
@NgModule({
...
providers: [ JPush ],
})
export class AppModule { }
- 在Component中调用方法
//...
import { JPush } from 'ionic3-jpush';
@Component({
template: `
<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
constructor (public jPush: JPush){
this.jPush.getRegistrationID().then(regid => {
console.log(regid)
})
}
}
实现方法
因项目需求只实现了目前项目中使用到的方法,如需更多方法请提交issue
- init(): Promise;
- stopPush(): Promise;
- resumePush(): Promise;
- isPushStopped(): Promise;
- getRegistrationID(): Promise;
- setTagsWithAlias(tags?: string[], alias?: string): Promise;
- setTags(tags?: string[]): Promise;
- setAlias(alias?: string): Promise;
- setBadge(badgeNum?: number): Promise;
- getUserNotificationSettings(): Promise;
- openNotification(): Observable;
- receiveNotification(): Observable;
- receiveMessage(): Observable;