ionic2集成极光推送;

ionic2api:https://ionicframework.com/docs/

极光推送官网:https://www.jiguang.cn

android-怎么注册极光以及新建项目:https://docs.jiguang.cn/jpush/client/Android/android_3m/

ios-怎么注册极光以及新建项目:https://docs.jiguang.cn/jpush/client/iOS/ios_guide_new/

ioic项目搭建就不介绍了;

在现有的项目上集成jpush;

pack.json里添加:

{
..."scripts": {"clean": "ionic-app-scripts clean","build": "ionic-app-scripts build","lint": "ionic-app-scripts lint","ionic:build": "ionic-app-scripts build","ionic:serve": "ionic-app-scripts serve"},"dependencies": {"@jiguang-ionic/jpush": "^1.0.2","jpush-phonegap-plugin": "~3.3.4"},"cordova": {"plugins": {.."jpush-phonegap-plugin": {"APP_KEY": "极光appkey"}..},"platforms": ["android","ios"]}
}

参照官方文档:https://github.com/jpush/jpush-phonegap-plugin

因为我们用了ionic所以我们需要@jiguang-ionic/jpush包;

app.module.ts中增加:

import { JPush } from '@jiguang-ionic/jpush';
...providers: [...JPush,...]

注册极光

在app.component.ts里增加:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { JPush } from '@jiguang-ionic/jpush';import { HomePage } from '../pages/home/home';
@Component({templateUrl: 'app.html'
})
export class MyApp {rootPage:any = HomePage;constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, jpush: JPush) {platform.ready().then(() => {// Okay, so the platform is ready and our plugins are available.// Here you can do any higher level native things you might need.statusBar.styleDefault();splashScreen.hide();jpush.init();//注册极光jpush.setDebugMode(true);});}
}

监听推送home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { JPush } from '@jiguang-ionic/jpush';
import { Device } from '@ionic-native/device';@Component({selector: 'page-home',templateUrl: 'home.html'
})
export class HomePage {public registrationId: string;devicePlatform: string;sequence: number = 0;tagResultHandler = function(result) {var sequence: number = result.sequence;var tags: Array<string> = result.tags == null ? [] : result.tags;alert('Success!' + '\nSequence: ' + sequence + '\nTags: ' + tags.toString());};aliasResultHandler = function(result) {var sequence: number = result.sequence;var alias: string = result.alias;alert('Success!' + '\nSequence: ' + sequence + '\nAlias: ' + alias);};errorHandler = function(err) {var sequence: number = err.sequence;var code = err.code;alert('Error!' + '\nSequence: ' + sequence + '\nCode: ' + code);};constructor(public navCtrl: NavController, public jpush: JPush, device: Device) {this.devicePlatform = device.platform;document.addEventListener('jpush.openNotification', (event: any) => {alert('jpush.openNotification' + JSON.stringify(event));this.jpush.setBadge(0);this.jpush.setApplicationIconBadgeNumber(0);})document.addEventListener('jpush.receiveNotification', (event: any) => {var content;if (this.devicePlatform == 'Android') {content = event.alert;} else { content = event.aps.alert;}alert('Receive notification: ' + JSON.stringify(event));this.jpush.setBadge(0);this.jpush.setApplicationIconBadgeNumber(0);}, false);document.addEventListener('jpush.openNotification', (event: any) => {var content;if (this.devicePlatform == 'Android') {content = event.alert;} else {  // iOSif (event.aps == undefined) { // 本地通知content = event.content;} else {  // APNScontent = event.aps.alert;}} alert('open notification: ' + JSON.stringify(event));}, false);document.addEventListener('jpush.receiveLocalNotification', (event: any) => {// iOS(*,9) Only , iOS(10,*) 将在 jpush.openNotification 和 jpush.receiveNotification 中触发。var content;if (this.devicePlatform == 'Android') {} else {content = event.content;} alert('receive local notification: ' + JSON.stringify(event));}, false);}getRegistrationID() {this.jpush.getRegistrationID().then(rId => {this.registrationId = rId;});}setTags() {this.jpush.setTags({ sequence: this.sequence++, tags: ['Tag1', 'Tag2']}).then(this.tagResultHandler).catch(this.errorHandler);}addTags() {this.jpush.addTags({ sequence: this.sequence++, tags: ['Tag3', 'Tag4']}).then(this.tagResultHandler).catch(this.errorHandler);}checkTagBindState() {this.jpush.checkTagBindState({ sequence: this.sequence++, tag: 'Tag1' }).then(result => {var sequence = result.sequence;var tag = result.tag;var isBind = result.isBind;alert('Sequence: ' + sequence + '\nTag: ' + tag + '\nIsBind: ' + isBind);}).catch(this.errorHandler);}deleteTags() {this.jpush.deleteTags({ sequence: this.sequence++, tags: ['Tag4']}).then(this.tagResultHandler).catch(this.errorHandler);}getAllTags() {this.jpush.getAllTags({ sequence: this.sequence++ }).then(this.tagResultHandler).catch(this.errorHandler);}cleanTags() {this.jpush.cleanTags({ sequence: this.sequence++ }).then(this.tagResultHandler).catch(this.errorHandler);}setAlias() {this.jpush.setAlias({ sequence: this.sequence++, alias: 'TestAlias' }).then(this.aliasResultHandler).catch(this.errorHandler);}getAlias() {this.jpush.getAlias({ sequence: this.sequence++ }).then(this.aliasResultHandler).catch(this.errorHandler);}deleteAlias() {this.jpush.deleteAlias({ sequence: this.sequence++ }).then(this.aliasResultHandler).catch(this.errorHandler);}addLocalNotification() {if (this.devicePlatform == 'Android') {this.jpush.addLocalNotification(0, 'Hello JPush', 'JPush', 1, 5000);} else {this.jpush.addLocalNotificationForIOS(5, 'Hello JPush', 1, 'localNoti1');}}
}

具体api请查看官网文档,以上是在ts下的使用方式

ionic2集成极光推送相关推荐

  1. Java中集成极光推送实现给Android提送消息通知(附代码下载)

    场景 Android中集成极光推送实现推送消息通知与根据别名指定推送附示例代码下载: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details ...

  2. 集成极光推送遇到的问题

    文章目录 解决1: 2.您只需要将minsdkversion更改为21而不是16 这个问题有两种不同的答案,但我认为最合适的是第二种解决方案. 这是Google的官方解释: 原文: 翻译:对Andro ...

  3. 极光推送 android 最新,Android——快速集成极光推送-Go语言中文社区

    集成极光推送 1,首先肯定是注册,添加应用 2,开始自动集成比手动集成简单第一步 在 build.gradle defaultConfig { multiDexEnabledtrue applicat ...

  4. ionic4 集成极光推送jpush

    ionic4 集成极光推送jpush 1. 在极光官网注册.登录.创建应用 极光推送官网 应用包名要与config.xml一致 2.安装插件 ionic cordova plugin add jpus ...

  5. 极光推送 简书android,(Android)react-native集成极光推送

    在Android中使用reactnative集成极光推送步骤如下: (1)在AndroidManifest中声明网络权限,获取包名到极光推送官网添加应用,获取AppKey,该key需要注册到应用中以获 ...

  6. 李洪强iOS之集成极光推送二iOS 证书 设置指南

    李洪强iOS之集成极光推送二iOS 证书 设置指南 创建应用程序ID 登陆 iOS Dev Center 选择进入iOS Provisioning Portal. 在 iOS Provisioning ...

  7. Android第三方SDK集成 —— 极光推送

    前言: 本文前篇,可以帮助朋友们快速集成极光推送.本文后篇,是我自己项目实践的一些总结和心得,应该对读者们还是很有参考价值的,相信读完这篇文章,你会对极光推送有更加深入的理解,而不仅仅只是会集成而已. ...

  8. 跨平台应用开发进阶(十一) :uni-app 实现IOS原生APP-云打包集成极光推送(JG-JPUSH)详细教程

    文章目录 一.前言 二.资源 三.集成 四.遇到的问题及解决措施 4.1 IOS开发者证书无推送权限 4.2 manifest中并没有配置push模块.但云端打包ios就是一直报Code Signin ...

  9. vmei-day04-Jcenter方式集成极光推送

    今天主要写了一个小demo来集成极光推送的功能到项目 第一步,先看proj_gradle配置: buildscript {repositories {jcenter()}dependencies {c ...

最新文章

  1. R语言指数分布(exponential distribution)函数(dexp, pexp, qexp rexp)实战
  2. 刷手识别:确认过“掌静脉”找到对的人
  3. iOS9系统下SEGV_ACCERR问题的解决方案
  4. linux 系统时间是在哪里记录的,Linux系统如何记录时间
  5. android 等待圈_Android ProgressDialog 转圈圈-阿里云开发者社区
  6. java三大范_Java深度学习系列——数据库的三大范式
  7. 包含重复数字序列的全排列Python解法
  8. Science亮点!ExSeq:完整生物组织的原位空间转录组分析
  9. 分支语句---- if …… else if …… else
  10. 被扎克伯格销毁的笔记本,暗藏 Facebook 所有成败
  11. NPM 修复两个严重漏洞但无法确认是否已遭在野利用,可触发开源软件供应链攻击...
  12. C#泛型学习实例(简单易懂)
  13. 什么是宽带薪酬?宽带薪酬系统如何实施?
  14. uni-app ucharts无法显示
  15. Android布局深究(五)——GridLayout(网格布局)
  16. vasp测试计算机,科学网—PWSCF 自洽计算、kpoints测试和ecut测试 - 叶小球的博文
  17. 全闪存存储的VDI场景应用
  18. 带电插拔损坏设备原理_那些设备可以热插拔?
  19. 阿里云李津:公有云做的是信心与责任!
  20. 【VUE-编辑回显】

热门文章

  1. 清华大学计算机科学与技术 金融学,清华大学王牌专业有哪些
  2. 图对比学习入门 Contrastive Learning on Graph
  3. jiamimao – 文件加密最简法门
  4. Scratch(四十一):升级版垃圾分类
  5. IDEA版本彩虹屁插件,一个在你编程时疯狂称赞你的 IDEA扩展插件
  6. ❤️数据可视化❤️:基于Echarts + GeoJson实现的地图视觉映射散点(气泡)组件【8】 - 河北省
  7. 温度报警器c语言课程设计,温度报警器课程设计报告.doc
  8. python豆瓣影评_使用Python抓取豆瓣影评数据的方法
  9. 探岳android auto,不懂颗粒捕捉器的清洗?探岳车主发现清洗新大陆!
  10. 儿童电子体温计的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告