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 = ; 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();
this.jpush.setApplicationIconBadgeNumber();
}) 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();
this.jpush.setApplicationIconBadgeNumber();
}, false); document.addEventListener('jpush.openNotification', (event: any) => {
var content;
if (this.devicePlatform == 'Android') {
content = event.alert;
} else { // iOS
if (event.aps == undefined) { // 本地通知
content = event.content;
} else { // APNS
content = 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(, 'Hello JPush', 'JPush', , );
} else {
this.jpush.addLocalNotificationForIOS(, 'Hello JPush', , 'localNoti1');
}
}
}

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

ionic2集成极光推送的更多相关文章

  1. 1、Android Studio集成极光推送(Jpush) 报错 java.lang.UnsatisfiedLinkError: cn.jpush.android.service.PushProtoco

    Android studio 集成极光推送(Jpush) (华为手机)报错, E/JPush: [JPushGlobal] Get sdk version fail![获取sdk版本失败!] W/Sy ...

  2. Swift3集成极光推送

      现在很多程序都开始使用Swift开发了,但是第三方库大多数都是用OC写的,所以我们要使用Swift和OC混编.今天的内容主要讲Swift3.0集成极光推送. 1.准备工作   集成指南,极光上说的 ...

  3. C#—ASP.NET:集成极光推送(Push API v3)

    C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994   1.极光推送官 ...

  4. 李洪强iOS之集成极光推送三iOS集成指南

    李洪强iOS之集成极光推送三iOS集成指南 SDK说明 适用版本 本文匹配的 SDK版本:r2.1.5 以后.查看最近更新了解最新的SDK更新情况.使用Xcode 6及以上版本可以使用新版Push S ...

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

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

  6. 李洪强iOS之集成极光推送一iOS SDK概述

    李洪强iOS之集成极光推送一iOS SDK概述 JPush iOS 从上图可以看出,JPush iOS Push 包括 2 个部分,APNs 推送(代理),与 JPush 应用内消息. 红色部分是 A ...

  7. ThinkPHP 3.2.x 集成极光推送指北

    3.2版本已经过了维护生命周期,官方已经不再维护,请及时更新至5.0版本 -- ThinkPHP 官方仓库 以上,如果有条件,请关闭这个页面,然后升级至 ThinkPHP 5,如果由于各种各样的原因无 ...

  8. thinkphp3.2集成极光推送

    项目中用到了给客户端的推送功能,选用了极光推送,下面演示一下在thinkphp中集成极光推送 1.下载极光推送的php类,可以从笔者的git下载 地址:https://git.oschina.net/ ...

  9. Xamarin.Forms学习系列之Android集成极光推送

    一般App都会有消息推送的功能,如果是原生安卓或者IOS集成消息推送很容易,各大推送平台都有相关的Sample,但是关于Xamarin.Forms的消息推送集成的资料非常少,下面就说下Xamarin. ...

随机推荐

  1. bzoj1924: [Sdoi2010]所驼门王的宝藏

    陈年老题又来水一发啊啊啊 构图狗了一点,然后其实强连通缩点dij找最长路就没了. 没调出来有点气,直接打了第9个点的表.... 来逛blog的你教教我呗 #include<cstdio> ...

  2. c++ std

    高中只是听说过stl,每次问老师老师都会说“有毒,千万别学”,于是stl有毒的言论深深的印在我脑海,看到就恐惧,于是一直没有学,但是大学后确实很多用到stl的地方必须去学习了. 现在想想老师当年的说法 ...

  3. week3_notebooke1

    今日内容:编码集合深浅cpoy文件操作函数初始函数函数的返回值函数的传参 初识: # == 数值比较 # is 比较的是内存地址 # id 测试的是内存地址 # 小数据池 str int # int: ...

  4. (转载)Android项目实战(三十二):圆角对话框Dialog

    Android项目实战(三十二):圆角对话框Dialog   前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话 ...

  5. 解决JSP页面中文乱码插入到数据库的问题

    在JSP页面使用表单注册一个用户名的时候,查看到数据库里面的表中文显示乱码的情况有两种: 1.JSP页面传进来的参数中文就是乱码,则是前台的问题,这个时候写一个过滤器就好了,可以写如下的一个过滤器 p ...

  6. SQL Server-简单查询语句,疑惑篇

      前言 对于一些原理性文章园中已有大量的文章尤其是关于索引这一块,我也是花费大量时间去学习,对于了解索引原理对于后续理解查询计划和性能调优有很大的帮助,而我们只是一些内容进行概括和总结,这一节我们开 ...

  7. hdu 1072 广搜(逃离爆炸迷宫)

    题意: 在n×m的地图上,0表示墙,1表示空地,2表示人,3表示目的地,4表示有定时炸弹重启器.定时炸弹的时间是6,人走一步所需要的时间是1.每次可以上.下.左.右移动一格.当人走到4时如果炸弹的时间 ...

  8. 记一次mybatis<if>标签的问题

    前言 到底还是没理解清楚的锅~~~~搞了好久...啊啊啊啊 错误: There is no getter for property named 'name' in 'class java.lang.L ...

  9. [读书笔记] R语言实战 (六) 基本图形方法

    1.  条形图 barplot() #载入vcd包 library(vcd) #table函数提取各个维度计数 counts <- table(Arthritis$Improved) count ...

  10. jquery 终止循环

    jQuery中each类似于javascript的for循环 但不同于for循环的是在each里面不能使用break结束循环,也不能使用continue来结束本次循环,想要实现类似的功能就只能用ret ...