在ionic项目中使用极光推送实现推送 & 服务器端代码
2015-08-25 14:17
561 查看
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
server code:
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) } }
相关文章推荐
- C++栈学习——赋值运算法的重载
- Java中的日历类Calendar的常用方法(所有方法都在客户端测试过)
- 阿里笔试--软开C/C++
- Java批量插入数据
- 《Java溯本求源》-Java基本数据类型
- decorators.xml
- 安卓开发环境配置_windows7+Eclipse+SDK
- windows32位安装MYSQL-python1.2.3
- 面向接口编程详解(三)——模式研究
- POJ---3274-Gold Balanced Lineup(hash)
- 面向接口编程详解(三)——模式研究
- Java抽象类的特点
- java Jackson 库操作 json 的基本演示
- eclipse连接真机无log,显示log device is empty!的解决办法
- Java开发需要了解
- 面向接口编程详解(二)——编程实例
- 面向接口编程详解(二)——编程实例
- Spring 3 MVC hello world example
- [python]发送邮件(可带附件+转中文)
- IDEA Save Actions 类似Eclipse