在ionic项目中使用极光推送实现推送 & 服务器端代码
ionic start -a jPushDemo -i com.lawxin.fengkong jpushdemo blank
meteor add cordova:cn.jpush.phonegap.JPushPlugin@https://github.com/jpush/jpush-phonegap-plugin/tarball/f54252dd4f28874319c002cf0d066b6adb865c1f
http://ionichina.com/topic/54f96e7b59a9bdef119234a1
下载之后,手动修改以下文件,也可以实现。需要注意的是极光有延迟,稍后便能看到效果。
cn.jpush.phonegap.JPushPlugin.java
src/android/AndroidManifest.xml
src/ios/PushConfig.plist
source code:http://vdisk.weibo.com/s/ao-ZYIoZdUTFI
取设备ID
//在非登陆页使用
document.addEventListener("deviceready", function () {
//alert(10000)
if (undefined != window.plugins
&& undefined != window.plugins.jPushPlugin){
//alert("on phone");
//启动极光推送服务
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.getRegistrationID(function (result) { if (result){
var registrationID = result;
console.log("registrationID",registrationID);
//alert("init registrationID"+result);
//alert("init registrationID"+result);
}
//alert("init registrationID"+result);
console.log("result registrationID",registrationID);
});
}
}, false);
server code:
package main import (
"fmt"
"github.com/ylywyn/jpush-api-go-client"
) const (
appKey = ""
secret = ""
) func main() { //Platform
var pf jpushclient.Platform
pf.Add(jpushclient.ANDROID)
pf.Add(jpushclient.IOS)
//pf.Add(jpushclient.WINPHONE)
//pf.All() //Audience
var ad jpushclient.Audience
s := []string{"011364bb516","0000103808e"}
//ad.SetTag(s)
//ad.SetAlias(s)
ad.SetID(s)
//ad.All() //Notice
message := "您有1条消息风控信息,请注意查收"
var notice jpushclient.Notice
notice.SetAlert(message)
notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: message})
notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: message})
//notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"}) var msg jpushclient.Message
msg.Title = "风控宝"
msg.Content = message payload := jpushclient.NewPushPayLoad()
payload.SetPlatform(&pf)
payload.SetAudience(&ad)
payload.SetMessage(&msg)
payload.SetNotice(¬ice) bytes, _ := payload.ToBytes()
fmt.Printf("%s\r\n", string(bytes)) //push
c := jpushclient.NewPushClient(secret, appKey)
str, err := c.Send(bytes)
if err != nil {
fmt.Printf("err:%s", err.Error())
} else {
fmt.Printf("ok:%s", str)
}
}
在ionic项目中使用极光推送实现推送 & 服务器端代码的更多相关文章
- Ionic项目中使用极光推送
Ionic项目中使用极光推送-android 对于Ionic项目中使用消息推送服务,Ionic官方提供了ngCordova项目,这个里面的提供了用angularjs封装好的消息推送服务(官方文档) ...
- Ionic项目中使用极光推送-android
对于Ionic项目中使用消息推送服务,Ionic官方提供了ngCordova项目,这个里面的提供了用angularjs封装好的消息推送服务(官方文档),使用的是GitHub上的 PushPlugin ...
- ionic 项目中使用ngCordova插件$cordovaCamera筛选手机图库图片显示出来并上传
原文档请看http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/ionic%E5%9B%BE%E7%89%87%E4%B8%8A%E4%B ...
- Ionic项目中如何使用Native Camera
本文介绍如何在ionic项目中使用设备的camera. Ionic版本:v3.2.0 / 2017-05-10 / MIT Licensed / Release Notes ============= ...
- ionic 项目中 使用 sass
注: 1.先安装node-sass -->> npm install --save node-sass --registry=https://registry.npm.taobao.or ...
- ionic 项目中添加modal的步骤流程
1.首先在templates文件夹下面定义一个新页面,xxx.html,template文件夹在空项目里面是没有的,需要手动添加一个,放在WWW文件夹下面. <ion-modal-view> ...
- ionic项目中手机状态栏显示使用$cordovaStatusbar插件
在项目中发现Android和iOS在手机状态栏样式不一样,然后就查到有一个cordova插件可以解决这个问题 1.下载插件$cordovaStatusbar命令: cordova plugin add ...
- 在项目中那个少用if else 语句,精简代码,便于维护的方法(1)
一般我在写一个函数的时候,可能需要一个回调函数,例如: function loadQtipCode(dom, title, content, width, showcb, hidecb) { $(do ...
- 如何在gradle项目中添加额外非开源jar包并提交代码
前提:项目开发中,遇到一个地方需要用到公司自定义的jar包,然后要放到代码里又不方便提交到私服 具体实施: 首先在项目中增加一个 libs目录,然后把这种非开源又不在私服上的jar包扔进去, 然后打开 ...
随机推荐
- ruby YAML.load 和YAML.load_file区别
1. load( io ) Load a document from the current io stream. File.open( 'animals.yaml' ) { |yf| YAML::l ...
- 【翻译转载】【官方教程】Asp.Net MVC4入门指南(1): 入门介绍
1. Asp.Net MVC4 入门介绍 · 原文地址:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/ ...
- Oracle创建用户、表(1)
Oracle创建用户.表(1) 1. 连接 C:\Users\LEI>sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on ...
- Brackets安装angularjs插件
Brackets是Adobe公司研发的一款开源WEB前端开发框架,界面清爽简约,代码提示功能比较强大,而且支持第三方插件,其提供的插件库中有大量的对Brackets感兴趣的开发人员所开发的插件,使用者 ...
- Java中super关键字的作用与用法
Java中的super是什么?java中的super关键字是一个引用变量,用于引用父类对象.关键字“super”以继承的概念出现在类中.主要用于以下情况: 1.使用super与变量:当派生类和基类具有 ...
- 常用浏览器User-Agent大全
=======================PC浏览器======================== OperaMozilla/5.0 (Windows NT 6.1; WOW64) AppleW ...
- HDU 4283 You Are the One (区间DP,经典)
题意: 某校举行一场非诚勿扰,给定一个出场序列,表示n个人的屌丝值,如果他是第k个出场的,他的不满意度为(k-1)*diao[i].为了让所有人的屌丝值之和更小,导演设置一个栈,可以将部分人装进栈中, ...
- CF Gym 100187D Holidays (数学,递推)
题意:给n个元素,从n中选两个非空集合A和B.问有多少中选法? 递推: dp[n]表示元素个数为n的方案数,对于新来的一个元素,要么加入集合,要么不加入集合自成一个集合.加入集合有三种选择,A,B,E ...
- CentOS更改时区
1.编辑文件 vi /etc/sysconfig/clock 修改内容 ZONE="Asia/Shanghai" 2.覆盖旧时区文件 cp /usr/share/zoneinfo/ ...
- CPP-基础:c++读取ini文件
配置文件格式是[JP]K=2EC156673E 2F4240 5595F6 char str[50];GetPrivateProfileString("JP", "K&q ...