第十五章:集成JPUSH
如果不想自己搭建push server,则可以借助于第三方的api来实现push的功能,本文主要介绍ionic如何集成jpush。
具体步骤如下:
- 创建ionic应用:ionic_jpush。
- 申请jpush账号:创建应用,上传开发者证书,并且记录jpush_api_appkey。
- 安装jpush plugin
first way: cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
second way:cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
third way:
git clone https://github.com/jpush/jpush-phonegap-plugin.git
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
- 修改配置
找到路径:ionic_jpush\plugins\cn.jpush.phonegap.JPushPlugin\src\ios\PushConfig.plist,修改jpush_api_key,并且填写如下部分:
<key>APS_FOR_PRODUCTION</key>
<string>0</string>
- 在services中添加push工厂:
.factory('Push', function() {
var push;
return {
setBadge: function(badge) {
if (push) {
console.log('jpush: set badge', badge);
plugins.jPushPlugin.setBadge(badge);
}
},
setAlias: function(alias) {
if (push) {
console.log('jpush: set alias', alias);
plugins.jPushPlugin.setAlias(alias);
}
},
check: function() {
if (window.jpush && push) {
plugins.jPushPlugin.receiveNotificationIniOSCallback(window.jpush);
window.jpush = null;
}
},
init: function(notificationCallback) {
console.log('jpush: start init-----------------------');
push = window.plugins && window.plugins.jPushPlugin;
if (push) {
console.log('jpush: init');
plugins.jPushPlugin.init();
plugins.jPushPlugin.setDebugMode(true);
plugins.jPushPlugin.openNotificationInAndroidCallback = notificationCallback;
plugins.jPushPlugin.receiveNotificationIniOSCallback = notificationCallback;
}
}
};
})
- 在app.js的run中初始化jpush并添加监听事件:其中请修改别名“12345678”成为你想要的name。
.run(function($ionicPlatform,Push) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
//jpush callback method
var notificationCallback = function(data) {
console.log('received data :' + data);
var notification = angular.fromJson(data);
//app 是否处于正在运行状态
var isActive = notification.notification;
// here add your code
//ios
if (ionic.Platform.isIOS()) {
window.alert(notification);
} else {
//非 ios(android)
}
};
//初始化
Push.init(notificationCallback);
//设置别名
Push.setAlias("12345678");
console.log('start to define addEventListener');
var onOpenNotification= function(event) {
console.log("JPushPlugin:onOpenNotification is triggered");
};
var onBackgroundNotification = function(event){
console.log("JPushPlugin:onBackgroundNotification is triggered");
};
var onReceiveNotification = function(event){
console.log("JPushPlugin:onReceiveNotification is triggered");
};
console.log('end to define addEventListener');
console.log('start to add addEventListener');
document.addEventListener("jpush.openNotification", onOpenNotification, false);
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false);
console.log('end to add addEventListener');
});
})
- 编译ios项目:
ionic build iOS
- 使用xcode打开工程:进行证书配置,确保使用的开发者证书有apns的权限。
- 在jpush官网中进行push模拟。
- 编译Android项目:
ionic build android
- 使用Android Studio打开工程:确保Jpush的包名和Project的包名是一样的。
- 在jpush官网进行push模拟。
常见问题:
- ios编译失败等一系列问题:最好请有经验的ios开发人员帮忙排查。
- 无法连接到jpush服务器:请检查api_key是否正确。
- 无法接收push信息:请检查jpush官网的push证书配置是否正确。
参考资料:
第十五章:集成JPUSH的更多相关文章
- Gradle 1.12 翻译——第十五章. 任务详述
有关其他已翻译的章节请关注Github上的项目:https://github.com/msdx/gradledoc/tree/1.12,或访问:http://gradledoc.qiniudn.com ...
- Gradle 1.12用户指南翻译——第二十五章. Scala 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
- Gradle 1.12用户指南翻译——第三十五章. Sonar 插件
本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- Gradle 1.12用户指南翻译——第六十五章. Maven 发布(新)
其他章节的翻译请参见:http://blog.csdn.net/column/details/gradle-translation.html翻译项目请关注Github上的地址:https://gith ...
- 15第十五章UDF用户自定义函数(转载)
15第十五章UDF用户自定义函数 待补上 原文链接 本文由豆约翰博客备份专家远程一键发布
- 《Linux命令行与shell脚本编程大全》 第十五章 学习笔记
第十五章:控制脚本 处理信号 重温Linux信号 信号 名称 描述 1 HUP 挂起 2 INT 中断 3 QUIT 结束运行 9 KILL 无条件终止 11 SEGV 段错误 15 TERM 尽可能 ...
- CSS3秘笈复习:十三章&十四章&十五章&十六章&十七章
第十三章 1.在使用浮动时,源代码的顺序非常重要.浮动元素的HTML必须处在要包围它的元素的HTML之前. 2.清楚浮动: (1).在外围div的底部添加一个清除元素:clear属性可以防止元素包围浮 ...
- Gradle 1.12用户指南翻译——第四十五章. 应用程序插件
本文由CSDN博客貌似掉线翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...
- “全栈2019”Java多线程第三十五章:如何获取线程被等待的时间?
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- “全栈2019”Java多线程第二十五章:生产者与消费者线程详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
随机推荐
- 软件工程:Java实现WC.exe基本功能
项目相关要求 GitHub地址:https://github.com/3216004716/WC 实现一个统计程序,它能正确统计程序文件中的字符数.单词数.行数,以及还具备其他扩展功能,并能够快速地处 ...
- delphi xe6 for android 自带控件LocationSensor优先使用GPS定位的方法
delphi xe6 for android LocationSensor控件默认是优先使用网络定位,对定位精度要求高的应用我们可以修改原码直接指定GPS定位. 修改方法: 将C:\Program F ...
- ComicEnhancerPro 系列教程十七:二值化图像去毛刺
作者:马健邮箱:stronghorse_mj@hotmail.com 主页:http://www.comicer.com/stronghorse/ 发布:2017.07.23 教程十七:二值化图像去毛 ...
- Win7 WPF程序无法接受外部拖拽
最近在WPF项目中遇到一个问题.虽然选择了AllowDrop = True,但是还是无法支持从外部拖拽文件到程序,倒是内部拖拽(如从一个列表拖拽到树)和从程序拖拽到外部可以. 解决过程 1.考虑是程序 ...
- webservice不能序列化接口问题,返回值为IList或者参数为接口的解决办法。
1. webservice 不能返回泛型接口集合IList,解决办法如下链接: 参考资料:http://www.cnblogs.com/yinhaiming/articles/1379424.html ...
- 十七、创建一个 WEB 服务器(一)
1.Node.js 创建的第一个应用 var http=require("http") http.createServer(function (req,res) { res.wri ...
- 上课总结-模电chapter 2
1.无明显失真时电压放大倍数——输出与输入电压的变化量之比 .无明显失真时 电流放大倍数——输出与输入电流的变化量之比 3.最大输出幅度 ①无明显失真时最大输出电压(或最大输出电流) ②交流有效值(U ...
- #论文笔记# [pix2pixHD] High-Resolution Image Synthesis and Semantic Manipulation with Conditional GANs
Ting-Chun Wang, Ming-Yu Liu, Jun-Yan Zhu, Andrew Tao, Jan Kautz, and Bryan Catanzaro. "High-Res ...
- 用Python写一个随机密码生成器
# /bin/python3 import sys import time import random strs = [ i for i in range(32,128) ] #产生密码的ASCII码 ...
- jvm学习笔记之对象详解
一.对象的组成 对象头(Header): 运行时数据:存储对象运行时的数据,如哈希码.GC分代年龄.锁状态标志.线程持有的锁.偏向线程ID.偏向时间戳等,这部分数据官方成为“Mark Word”,它的 ...