jpush-phonegap-plugin/document/iOS_detail_api.md

216 lines
5.9 KiB
Markdown
Raw Normal View History

2015-04-14 09:58:44 +08:00
## iOS API简介
### 获取 APNs通知 推送内容
#### event - jpush.receiveNotification
当iOS收到的通知时会触发这个事件
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
- onOpenNotification需要这样写
var onReceiveNotification = function(event){
try{
var alert = event.aps.alert;
console.log("JPushPlugin:onReceiveNotification key aps.alert:"+alert);
}
catch(exeption){
console.log(exception)
}
}
#### event - jpush.openNotification
点击通知进入应用程序时会出发改事件
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.openNotification", onOpenNotification, false);
- onOpenNotification需要这样写
var onOpenNotification = function(event){
try{
var alert = event.aps.alert;
console.log("JPushPlugin:onPpenNotification key aps.alert:"+alert);
}
catch(exception){
console.log("JPushPlugin:onPpenNotification"+exception);
}
}
2015-04-14 09:58:44 +08:00
### 获取自定义消息推送内容
####event - jpush.receiveMessage
收到应用内消息时触发这个事件
`推荐使用事件的方式传递但同时保留了receiveMessageIniOSCallback的回调函数兼容以前的代码`
#####代码示例
- 在你需要接收通知的的js文件中加入:
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
- onReceiveMessage需要这样写
var onReceiveMessage = function(event){
try{
var eventMessage="{";
for(var key in event){
if(key=="type"){
break
}
eventMessage+=key+":"+JSON.stringify(event[key])+"\n"
console.log(key+":"+JSON.stringify(event[key]));
}
eventMessage+="}";
$("#messageResult").html(eventMessage);
}
catch(exception){
console.log("JPushPlugin:onReceiveMessage"+exception);
}
}
2015-04-14 09:58:44 +08:00
#### API - receiveMessageIniOSCallback
用于iOS收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
不推荐使用回调函数
2015-04-14 09:58:44 +08:00
##### 接口定义
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data)
#####参数说明
- data 是一个js字符串使用如下代码解析js具体key根据应用内消息来确定
var bToObj = JSON.parse(data);
#####返回值
##### 代码示例
### 页面的统计
#### API - startLogPageView,stopLogPageView,beginLogPageView
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确才能够获取正确的页面访问路径、访问深度PV的数据。
##### 接口定义
window.plugins.jPushPlugin.startLogPageView = function(pageName)
window.plugins.jPushPlugin.stopLogPageView = function(pageName)
window.plugins.jPushPlugin.beginLogPageView = function(pageName,duration)
2015-04-14 09:58:44 +08:00
#####参数说明
pageName 需要统计页面自定义名称
duration 自定义的页面时间
#####调用说明
应在所有的需要统计得页面得 viewWillAppear 和 viewWillDisappear 加入 startLogPageView 和 stopLogPageView 来统计当前页面的停留时间。
或者直接使用 beginLogPageView 来自定义加入页面和时间信息。
#####返回值说明
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
window.plugins.jPushPlugin.startLogPageView("onePage");
window.plugins.jPushPlugin.stopLogPageView("onePage");
}
### 设置Badge
#### API - setBadge,resetBadge
badge是iOS用来标记应用程序状态的一个数字出现在程序图标右上角。 JPush封装badge功能允许应用上传badge值至JPush服务器由JPush后台帮助管理每个用户所对应的推送badge值简化了设置推送badge的操作。
实际应用中开发者可以直接对badge值做增减操作无需自己维护用户与badge值之间的对应关系。
##### 接口定义
window.plugins.jPushPlugin.setBadge(value)
window.plugins.jPushPlugin.reSetBadge()
2015-04-14 09:58:44 +08:00
`resetBadge相当于setBadge(0)`
##### 参数说明
value 取值范围:[0,99999]
##### 返回值
控制台会有log打印设置结果
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setBadge(5);
window.plugins.jPushPlugin.reSetBadge();
}
#### API - setApplicationIconBadgeNumber
设置iOS的角标当设置badge0时为清除角标
##### 接口定义
window.plugins.jPushPlugin.reSetBadge.setApplicationIconBadgeNumber(badge)
2015-04-14 09:58:44 +08:00
##### 参数说明
- badge 整形,例如012
- 当badge为0时角标被清除
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.reSetBadge.setApplicationIconBadgeNumber(0);
2015-04-14 09:58:44 +08:00
}
### 本地通知
### 日志等级设置
#### API - setDebugModeFromIos
API 用于开启Debug模式显示更多的日志信息
建议调试时开启这个选项不调试的时候注释这句代码这个函数setLogOFF是相反的一对
##### 接口定义
window.plugins.jPushPlugin.reSetBadge.setDebugModeFromIos()
2015-04-14 09:58:44 +08:00
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setDebugModeFromIos();
}
#### API - setLogOFF
API用来关闭日志信息除了必要的错误信息
不需要任何调试信息的时候调用此API 发布时建议调用此API用来屏蔽日志信息节省性能消耗)
##### 接口定义
window.plugins.jPushPlugin.reSetBadge.setLogOFF ()
2015-04-14 09:58:44 +08:00
#####代码示例
if(window.plugins.jPushPlugin.isPlatformIOS()){
window.plugins.jPushPlugin.setLogOFF();
}