mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-02-08 00:05:13 +08:00
Compare commits
74 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dba1a4c5e | ||
|
|
d7fc0d2248 | ||
|
|
66729b7337 | ||
|
|
a3082d0475 | ||
|
|
3868e0be35 | ||
|
|
40c98f4f04 | ||
|
|
032b6f5d0c | ||
|
|
b4c02a96d5 | ||
|
|
381395acaf | ||
|
|
cf39b64bfc | ||
|
|
c74b8372c0 | ||
|
|
41bb3f871e | ||
|
|
ff090d63f6 | ||
|
|
c5c6b3da06 | ||
|
|
6cee953edd | ||
|
|
afe2230ed9 | ||
|
|
5c5d7c7848 | ||
|
|
416e41cb00 | ||
|
|
7d4b6acacd | ||
|
|
dde913b922 | ||
|
|
4d0ff548b8 | ||
|
|
83e86b64de | ||
|
|
d5cf71ed1e | ||
|
|
1536d737ad | ||
|
|
3f9454edf3 | ||
|
|
3d46fbc9ba | ||
|
|
6f826ca9ba | ||
|
|
f2eb889584 | ||
|
|
34c316af7e | ||
|
|
e7bedc78f7 | ||
|
|
23fd3bc0cb | ||
|
|
5e44499ff5 | ||
|
|
b13aabe2bc | ||
|
|
7cb3e22e14 | ||
|
|
a3ad96f786 | ||
|
|
42d64ca2f0 | ||
|
|
0af2f60dbb | ||
|
|
0da9f0ed26 | ||
|
|
f3bc83d97b | ||
|
|
8b674bb777 | ||
|
|
181ab80dab | ||
|
|
de59d7919b | ||
|
|
1102ad3a57 | ||
|
|
a8e4060b4d | ||
|
|
3b234f3101 | ||
|
|
7c580b4eaf | ||
|
|
af267eda94 | ||
|
|
d93b35611b | ||
|
|
d94ccfb8d8 | ||
|
|
b24b7064ba | ||
|
|
f12e7a35d0 | ||
|
|
37c1d308eb | ||
|
|
c2818fb193 | ||
|
|
32d3ecc917 | ||
|
|
138fde1587 | ||
|
|
f54252dd4f | ||
|
|
96c27448a0 | ||
|
|
2211e68e68 | ||
|
|
6a74a1697b | ||
|
|
3196aeff72 | ||
|
|
ca2e52fe54 | ||
|
|
a2c311730d | ||
|
|
f624670b4f | ||
|
|
5ade8c3300 | ||
|
|
c2f957acbe | ||
|
|
b10bc7dbb4 | ||
|
|
126e54d5b1 | ||
|
|
c826b0d94a | ||
|
|
79d0b5e037 | ||
|
|
5836cac41f | ||
|
|
8ea95cd5ef | ||
|
|
ef339a1b96 | ||
|
|
0233a10906 | ||
|
|
cb8f8412b4 |
159
README.md
159
README.md
@@ -1,93 +1,66 @@
|
||||
l## JPush PhoneGap Plugin ##
|
||||
## JPush PhoneGap Plugin ##
|
||||
|
||||
jpush-phonegap-plugin 支持 iOS,Android 的推送插件。
|
||||
|
||||
**功能特性:**
|
||||
>+ 发送推送通知
|
||||
+ 发送推送自定义消息
|
||||
+ 设置推送标签和别名
|
||||
+ 设置角标(iOS)
|
||||
|
||||
*如需要 IM 功能插件,请关注[jmessage-phonegap-plugin](https://github.com/jpush/jmessage-phonegap-plugin)*
|
||||
|
||||
|
||||
## 安装 ##
|
||||
###准备工作
|
||||
|
||||
1. cordova create 文件夹名字 包名 应用名字
|
||||
|
||||
cordova create Myproj com.myproj.jpush MyTestProj
|
||||
|
||||
|
||||
2. 添加平台
|
||||
|
||||
cd Myproj
|
||||
cd Myproj
|
||||
cordova platform add android
|
||||
cordova platform add ios
|
||||
|
||||
ps:这里请注意iOS平台,必须先执行 `cordova platform add ios`,
|
||||
然后再执行`cordova plugin add xxxxx`命令,不然有一些必须要的链接库需要手动添加
|
||||
|
||||
|
||||
|
||||
###Cordova CLI/Phonegap 安装 Android & iOS
|
||||
|
||||
3. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
1). 安装JPush PhoneGap Plugin。 有两种方法。
|
||||
|
||||
方法一: 在线安装
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
|
||||
方法二:下载到本地再安装
|
||||
|
||||
使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
|
||||
4. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)
|
||||
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||
|
||||
5. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest)
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
||||
|
||||
|
||||
6. cordova cli 添加jpush phonegap插件和依赖的device插件:
|
||||
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR
|
||||
cordova plugin add org.apache.cordova.device
|
||||
2). 安装org.apache.cordova.device
|
||||
|
||||
7. iOS添加初始化JPush sdk代码 如果你要先部署android平台,可以先忽略这一步,当需要iOS 平台时,只加上这个步骤即可
|
||||
|
||||
+ 用xcode 打开 Myproj下的iOS工程
|
||||
+ 打开xcode右边工程目录下`Resources/PushConfig.plist`
|
||||
|
||||
在APP_KEY和CHANNLE字段 分别添加您的appkey和channle
|
||||
|
||||
+ 打开xcode右边工程目录下`AppDelegate.m`,包含以下头文件
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
#import "APService.h"
|
||||
#import "JPushPlugin.h"
|
||||
|
||||
+ 在AppDelegate.m文件中,添加JPush SDK 提供的 API 来实现功能
|
||||
3). 在js中调用函数,初始化jpush sdk
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
|
||||
//原内容保持不变
|
||||
//Required add
|
||||
[JPushPlugin setLaunchOptions:launchOptions];
|
||||
return YES;
|
||||
}
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
//原内容保持不变
|
||||
// Required add
|
||||
[APService registerDeviceToken:deviceToken];
|
||||
}
|
||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
||||
//原内容保持不变
|
||||
// Required
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
}
|
||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
// IOS 7 Support Required
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
|
||||
completionHandler(UIBackgroundFetchResultNewData);
|
||||
}
|
||||
|
||||
|
||||
7. 在js中调用函数,初始化jpush sdk
|
||||
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
### Android 手工安装
|
||||
|
||||
[Android 手工安装文档地址](document/Android_handle_install.md)
|
||||
|
||||
|
||||
|
||||
### IOS手工安装
|
||||
|
||||
@@ -106,12 +79,6 @@ l## JPush PhoneGap Plugin ##
|
||||
|
||||
该项目基于cordova实现,目前无法使用'phonegap build'云服务进行打包,建议使用本地环境进行打包
|
||||
|
||||
###常见错误
|
||||
1. androd
|
||||
|
||||
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
||||
|
||||
### API说明
|
||||
|
||||
插件的API集中在JPushPlugin.js文件中,这个文件的位置如下
|
||||
@@ -121,10 +88,10 @@ l## JPush PhoneGap Plugin ##
|
||||
|
||||
具体的API请参考这里
|
||||
|
||||
#### iOS和adnroid通用API简介
|
||||
#### iOS和android通用API简介
|
||||
|
||||
+ 停止与恢复推送服务 API
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.init()
|
||||
window.plugins.jPushPlugin.stopPush()
|
||||
window.plugins.jPushPlugin.resumePush()
|
||||
@@ -134,17 +101,17 @@ l## JPush PhoneGap Plugin ##
|
||||
+ 获取 RegistrationID API
|
||||
|
||||
window.plugins.jPushPlugin.getRegistrationID(callback)
|
||||
|
||||
|
||||
+ 别名与标签 API
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(tags,alias)
|
||||
window.plugins.jPushPlugin.setTags(tags)
|
||||
window.plugins.jPushPlugin.setAlias(alias)
|
||||
+ 获取点击通知内容
|
||||
|
||||
|
||||
event - jpush.openNotification
|
||||
+ 获取通知内容
|
||||
|
||||
|
||||
event - jpush.receiveNotification
|
||||
|
||||
+ 获取自定义消息推送内容
|
||||
@@ -161,9 +128,9 @@ l## JPush PhoneGap Plugin ##
|
||||
event - jpush.receiveMessage
|
||||
//推荐使用事件的方式传递,但同时保留了receiveMessageIniOSCallback的回调函数,兼容以前的代码
|
||||
window.plugins.jPushPlugin.receiveMessageIniOSCallback(data)
|
||||
|
||||
|
||||
+ 页面的统计
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.startLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView (pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView (pageName,duration)
|
||||
@@ -175,31 +142,36 @@ l## JPush PhoneGap Plugin ##
|
||||
+ 本地通知
|
||||
|
||||
+ 后续版本加入
|
||||
|
||||
|
||||
+ 日志等级设置
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos ()
|
||||
window.plugins.jPushPlugin.setLogOFF()
|
||||
|
||||
|
||||
|
||||
|
||||
[iOS API详细说明](document/iOS_detail_api.md)
|
||||
|
||||
|
||||
#### adnroid API简介
|
||||
|
||||
#### android API简介
|
||||
|
||||
+ 获取集成日志
|
||||
window.plugins.jPushPlugin.setDebugMode(mode)
|
||||
|
||||
+ 接收推送消息和点击通知
|
||||
|
||||
|
||||
//下面这两个api 是兼容旧有的代码
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback(data)
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback(data)
|
||||
|
||||
+ 统计分析 API
|
||||
|
||||
onResume / onPause(java api)
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
或在 MainActivity 中的 onPause() 和 onResume() 方法中分别调用
|
||||
JPushInterface.onResume(this) 和 JPushInterface.onPause(this) 来启用统计分析功能,
|
||||
如果使用这种方式启用统计分析功能,则window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
方法不再有效,建议不要同时使用。
|
||||
|
||||
+ 清除通知 API
|
||||
|
||||
window.plugins.jPushPlugin.clearAllNotification()
|
||||
@@ -210,11 +182,11 @@ l## JPush PhoneGap Plugin ##
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
|
||||
+ 设置保留最近通知条数 API
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
|
||||
+ 本地通知API
|
||||
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotification(builderId,
|
||||
content,
|
||||
title,
|
||||
@@ -226,5 +198,20 @@ l## JPush PhoneGap Plugin ##
|
||||
|
||||
[Android API详细说明](document/Android_detail_api.md)
|
||||
|
||||
###常见问题
|
||||
|
||||
####1. android
|
||||
|
||||
eclipse中phonegap工程import之后出现:`Type CallbackContext cannot be resolved to a type`
|
||||
解决方案:eclipse中右键单击工程名,Build Path->Config Build Path->Projects->选中 工程名称-CordovaLib->点击 add
|
||||
|
||||
####2. iOS 设置/修改 APP_KEY
|
||||
|
||||
在PushConfig.plist 中修改。PushConfig.plist 其他值说明:
|
||||
CHANNEL 渠道标识
|
||||
IsProduction 是否生产环境(暂未启用)
|
||||
|
||||
|
||||
|
||||
###更多
|
||||
[JPush官网文档](http://docs.jpush.io/)
|
||||
[JPush官网文档](http://docs.jpush.io/)
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.receiveMessageInAndroidCallback = function(data)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
- data 接收到的js字符串,包含的key:value请进入该函数体查看
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
- data js字符串
|
||||
|
||||
@@ -80,6 +80,19 @@
|
||||
JPushInterface.onPause(this);
|
||||
}
|
||||
|
||||
#### API - setStatisticsOpen(boolean)
|
||||
|
||||
用于在 js 中控制是否打开应用的统计分析功能,但如果已经添加了上面的 onResume/onPause 方法,
|
||||
就不能再通过这个方法来控制统计分析功能了。
|
||||
|
||||
#### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(boolean)
|
||||
|
||||
#### 参数说明
|
||||
- boolean
|
||||
-true : 打开统计分析功能
|
||||
-false: 关闭统计分析功能
|
||||
|
||||
#### API - reportNotificationOpened
|
||||
|
||||
@@ -89,7 +102,7 @@
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reportNotificationOpened(msgID)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
- msgID
|
||||
-收到的通知或者自定义消息的id
|
||||
@@ -117,14 +130,14 @@
|
||||
当用户需要定制默认的通知栏样式时,则可调用此方法。
|
||||
极光 Push SDK 提供了 2 个用于定制通知栏样式的构建类:
|
||||
|
||||
- setBasicPushNotificationBuilder
|
||||
- setBasicPushNotificationBuilder
|
||||
- Basic 用于定制 Android Notification 里的 defaults / flags / icon 等基础样式(行为)
|
||||
- setCustomPushNotificationBuilder
|
||||
- 继承 Basic 进一步让开发者定制 Notification Layout
|
||||
|
||||
|
||||
如果不调用此方法定制,则极光Push SDK 默认的通知栏样式是:Android标准的通知栏提示。
|
||||
|
||||
##### 接口定义
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBasicPushNotificationBuilder = function()
|
||||
window.plugins.jPushPlugin.setCustomPushNotificationBuilder = function()
|
||||
@@ -143,7 +156,7 @@
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setLatestNotificationNum(num)
|
||||
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- num 保存的条数
|
||||
@@ -181,5 +194,3 @@
|
||||
- notificaitonID 设置本地通知的ID
|
||||
- broadcastTime 设置本地通知触发时间,为距离当前时间的数值,单位是毫秒
|
||||
- extras 设置额外的数据信息extras为json字符串
|
||||
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到cn/jpush/phonega/目录下(即:cn.jpush.phonegap的包下)
|
||||
2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到lib/armeabi/
|
||||
3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release1.5.0.jar 到lib/
|
||||
3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release2.0.6.jar 到lib/
|
||||
4. 复制:`$JPUSH_PLUGIN_DIR`/src/android/test_notification_layout.xml到res/layout/
|
||||
5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png 到res/drawable/
|
||||
5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png到res/drawable/
|
||||
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
@@ -53,7 +53,7 @@
|
||||
<action android:name="cn.jpush.android.intent.REPORT"/>
|
||||
<action android:name="cn.jpush.android.intent.PushService"/>
|
||||
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
|
||||
|
||||
|
||||
</intent-filter>
|
||||
</service>
|
||||
<!-- Required SDK核心功能-->
|
||||
@@ -76,7 +76,7 @@
|
||||
<data android:scheme="package"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
<!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||
<receiver
|
||||
android:name="cn.jpush.phonegap.MyReceiver"
|
||||
|
||||
@@ -271,7 +271,7 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
|
||||
|
||||
#### event - jpush.receiveNotification
|
||||
|
||||
点击通知进入应用程序时会出发改事件
|
||||
点击通知进入应用程序时会触发该事件
|
||||
|
||||
#####代码示例
|
||||
|
||||
@@ -284,7 +284,7 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.ope
|
||||
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.openNotification.alert;
|
||||
alertContent=window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.rec
|
||||
}
|
||||
}
|
||||
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
ps:点击通知后传递的json object 保存在window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意
|
||||
|
||||
+ android
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
- data 是一个js字符串使用如下代码解析,js具体key根据应用内消息来确定
|
||||
|
||||
var bToObj = JSON.parse(data);
|
||||
var bToObj = JSON.parse(data)
|
||||
|
||||
#####返回值
|
||||
无
|
||||
@@ -30,9 +30,9 @@
|
||||
本 API 用于“用户指定页面使用时长”的统计,并上报到服务器,在 Portal 上展示给开发者。页面统计集成正确,才能够获取正确的页面访问路径、访问深度(PV)的数据。
|
||||
|
||||
##### 接口定义
|
||||
window.plugins.jPushPlugin.startLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.stopLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.beginLogPageView = function(pageName,duration)
|
||||
window.plugins.jPushPlugin.prototype.startLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.prototype.stopLogPageView = function(pageName)
|
||||
window.plugins.jPushPlugin.prototype.beginLogPageView = function(pageName,duration)
|
||||
#####参数说明
|
||||
pageName 需要统计页面自定义名称
|
||||
duration 自定义的页面时间
|
||||
@@ -44,21 +44,21 @@ duration 自定义的页面时间
|
||||
无
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.beginLogPageView("newPage",5);
|
||||
window.plugins.jPushPlugin.startLogPageView("onePage");
|
||||
window.plugins.jPushPlugin.stopLogPageView("onePage");
|
||||
}
|
||||
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的操作。
|
||||
JPush封装badge功能,允许应用上传badge值至JPush服务器,由JPush后台帮助管理每个用户所对应的推送badge值,简化了设置推送badge的操作。
|
||||
(本接口不会直接改变应用本地的角标值. 要修改本地badege值,使用 setApplicationIconBadgeNumber)
|
||||
|
||||
实际应用中,开发者可以直接对badge值做增减操作,无需自己维护用户与badge值之间的对应关系。
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setBadge(value)
|
||||
window.plugins.jPushPlugin.reSetBadge()
|
||||
window.plugins.jPushPlugin.prototype.setBadge(value)
|
||||
window.plugins.jPushPlugin.prototype.reSetBadge()
|
||||
|
||||
`resetBadge相当于setBadge(0)`
|
||||
##### 参数说明
|
||||
@@ -67,18 +67,17 @@ value 取值范围:[0,99999]
|
||||
无,控制台会有log打印设置结果
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
}
|
||||
window.plugins.jPushPlugin.setBadge(5);
|
||||
window.plugins.jPushPlugin.reSetBadge();
|
||||
|
||||
#### API - setApplicationIconBadgeNumber
|
||||
|
||||
本接口直接改变应用本地的角标值.
|
||||
设置iOS的角标,当设置badge=0时为清除角标
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(badge)
|
||||
window.plugins.jPushPlugin.prototype.setApplicationIconBadgeNumber(badge)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
@@ -87,13 +86,81 @@ value 取值范围:[0,99999]
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
}
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
|
||||
|
||||
#### API - getApplicationIconBadgeNumber
|
||||
|
||||
获取iOS的角标值
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.getApplicationIconBadgeNumber(callback)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- callback 回调函数
|
||||
|
||||
#####代码示例
|
||||
```
|
||||
|
||||
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
### 本地通知
|
||||
#### API - addLocalNotificationForIOS
|
||||
|
||||
API用于注册本地通知
|
||||
|
||||
最多支持64个
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.addLocalNotificationForIOS(delayTime,content,badge,notificationID,extras)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- delayTime 本地推送延迟多长时间后显示,数值类型或纯数字的字符型均可
|
||||
- content 本地推送需要显示的内容
|
||||
- badge 角标的数字。如果不需要改变角标传-1。数值类型或纯数字的字符型均可
|
||||
- notificationID 本地推送标识符,字符串。
|
||||
- extras 自定义参数,可以用来标识推送和增加附加信息。字典类型。
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.addLocalNotificationForIOS(6*60*60,"本地推送内容",1,"notiId",{"key":"value"});
|
||||
|
||||
#### API - deleteLocalNotificationWithIdentifierKeyInIOS
|
||||
|
||||
API删除本地推送定义
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS(identifierKey)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- identifierKey 本地推送标识符
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
|
||||
|
||||
#### API - clearAllLocalNotifications
|
||||
|
||||
API清除所有本地推送对象
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.clearAllLocalNotifications()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.clearAllLocalNotifications();
|
||||
|
||||
### 日志等级设置
|
||||
#### API - setDebugModeFromIos
|
||||
API 用于开启Debug模式,显示更多的日志信息
|
||||
@@ -101,13 +168,11 @@ API 用于开启Debug模式,显示更多的日志信息
|
||||
建议调试时开启这个选项,不调试的时候注释这句代码,这个函数setLogOFF是相反的一对
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reSetBadge.setDebugModeFromIos()
|
||||
window.plugins.jPushPlugin.prototype.setDebugModeFromIos()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
}
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
|
||||
#### API - setLogOFF
|
||||
|
||||
@@ -117,11 +182,56 @@ API用来关闭日志信息(除了必要的错误信息)
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.reSetBadge.setLogOFF ()
|
||||
window.plugins.jPushPlugin.prototype.setLogOFF()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
}
|
||||
window.plugins.jPushPlugin.setLogOFF();
|
||||
|
||||
#### API - setCrashLogON
|
||||
|
||||
API用于统计用户应用崩溃日志
|
||||
|
||||
如果需要统计Log信息,调用该接口。当你需要自己收集错误信息时,切记不要调用该接口。
|
||||
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setCrashLogON()
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setCrashLogON();
|
||||
|
||||
### 地理位置上报
|
||||
#### API - setLocation
|
||||
API 用于统计用户地理信息
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.setLocation(latitude,longitude)
|
||||
|
||||
##### 参数说明
|
||||
|
||||
- latitude 地理位置纬度,数值类型或纯数字的字符型均可
|
||||
- longitude 地理位置精度,数值类型或纯数字的字符型均可
|
||||
|
||||
#####代码示例
|
||||
|
||||
window.plugins.jPushPlugin.setLocation(39.26,115.25);
|
||||
|
||||
### 设备平台判断
|
||||
#### API - isPlatformIOS
|
||||
API 用于区分iOS、Android平台,以便不同设置
|
||||
|
||||
##### 接口定义
|
||||
|
||||
window.plugins.jPushPlugin.prototype.isPlatformIOS()
|
||||
|
||||
#####代码示例
|
||||
|
||||
if(window.plugins.jPushPlugin.isPlatformIOS()){
|
||||
//iOS
|
||||
}else{
|
||||
//Android
|
||||
}
|
||||
|
||||
@@ -1,210 +1,223 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Phonegap Sample App</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript">
|
||||
var onDeviceReady = function(){
|
||||
console.log("JPushPlugin:Device ready!")
|
||||
initiateUI();
|
||||
}
|
||||
var onGetRegistradionID = function(data) {
|
||||
try{
|
||||
console.log("JPushPlugin:registrationID is "+data)
|
||||
|
||||
$("#registrationid").html(data);
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Phonegap Sample App</title>
|
||||
<link href="css/jquery.mobile-1.1.1.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.mobile-1.1.1.js"></script>
|
||||
<script type="text/javascript" src="cordova.js"></script>
|
||||
<script type="text/javascript">
|
||||
var onDeviceReady = function () {
|
||||
console.log("JPushPlugin:Device ready!");
|
||||
initiateUI();
|
||||
};
|
||||
|
||||
function getRegistrationID() {
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
}
|
||||
|
||||
var onGetRegistradionID = function (data) {
|
||||
try {
|
||||
|
||||
console.log("JPushPlugin:registrationID is " + data);
|
||||
|
||||
if (data.length == 0) {
|
||||
var t1 = window.setTimeout(getRegistrationID, 1000);
|
||||
}
|
||||
catch(exception){
|
||||
$("#registrationid").html(data);
|
||||
}
|
||||
catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
};
|
||||
|
||||
var onTagsWithAlias = function (event) {
|
||||
try {
|
||||
console.log("onTagsWithAlias");
|
||||
var result = "result code:" + event.resultCode + " ";
|
||||
result += "tags:" + event.tags + " ";
|
||||
result += "alias:" + event.alias + " ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch (exception) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onOpenNotification = function (event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
alertContent = window.plugins.jPushPlugin.openNotification.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:" + alertContent);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
console.log("JPushPlugin:onOpenNotification" + exception);
|
||||
}
|
||||
};
|
||||
var onReceiveNotification = function (event) {
|
||||
try {
|
||||
var alertContent;
|
||||
if (device.platform == "Android") {
|
||||
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
} else {
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alertContent);
|
||||
|
||||
}
|
||||
catch (exeption) {
|
||||
console.log(exception)
|
||||
}
|
||||
};
|
||||
var onReceiveMessage = function (event) {
|
||||
try {
|
||||
|
||||
var message;
|
||||
if (device.platform == "Android") {
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
} else {
|
||||
message = event.content;
|
||||
}
|
||||
//var extras = window.plugins.jPushPlugin.extras
|
||||
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
console.log("JPushPlugin:onReceiveMessage-->" + exception);
|
||||
}
|
||||
};
|
||||
|
||||
var initiateUI = function () {
|
||||
|
||||
try {
|
||||
window.plugins.jPushPlugin.init();
|
||||
getRegistrationID();
|
||||
|
||||
if (device.platform != "Android") {
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
} else {
|
||||
window.plugins.jPushPlugin.setDebugMode(true);
|
||||
window.plugins.jPushPlugin.setStatisticsOpen(true);
|
||||
}
|
||||
}
|
||||
catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
$("#setTagWithAliasButton").click(function (ev) {
|
||||
|
||||
// window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data){
|
||||
// console.log(data);
|
||||
// });
|
||||
|
||||
try {
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
var tag2 = $("#tagText2").attr("value");
|
||||
var tag3 = $("#tagText3").attr("value");
|
||||
var alias = $("#aliasText").attr("value");
|
||||
var dd = [];
|
||||
|
||||
if (tag1 == "" && tag2 == "" && tag3 == "") {
|
||||
}
|
||||
else {
|
||||
if (tag1 != "") {
|
||||
dd.push(tag1);
|
||||
}
|
||||
if (tag2 != "") {
|
||||
dd.push(tag2);
|
||||
}
|
||||
if (tag3 != "") {
|
||||
dd.push(tag3);
|
||||
}
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(dd, alias);
|
||||
|
||||
}
|
||||
catch (exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
var onTagsWithAlias = function(event){
|
||||
try{
|
||||
console.log("onTagsWithAlias");
|
||||
var result="result code:"+event.resultCode+" ";
|
||||
result+="tags:"+event.tags+" ";
|
||||
result+="alias:"+event.alias+" ";
|
||||
$("#tagAliasResult").html(result);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onOpenNotification = function(event){
|
||||
try{
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alertContent=window.plugins.jPushPlugin.openNotification.alert;
|
||||
}else{
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
alert("open Notificaiton:"+alertContent);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onOpenNotification"+exception);
|
||||
}
|
||||
}
|
||||
var onReceiveNotification = function(event){
|
||||
try{
|
||||
var alert
|
||||
if(device.platform == "Android"){
|
||||
alert = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alert = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alert);
|
||||
|
||||
}
|
||||
catch(exeption){
|
||||
console.log(exception)
|
||||
}
|
||||
}
|
||||
var onReceiveMessage = function(event){
|
||||
try{
|
||||
|
||||
var message
|
||||
if(device.platform == "Android"){
|
||||
message = window.plugins.jPushPlugin.receiveMessage.message;
|
||||
}else{
|
||||
message = event.content;
|
||||
}
|
||||
//var extras = window.plugins.jPushPlugin.extras
|
||||
|
||||
$("#messageResult").html(message);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:onReceiveMessage-->"+exception);
|
||||
}
|
||||
}
|
||||
|
||||
var initiateUI = function(){
|
||||
|
||||
try{
|
||||
window.plugins.jPushPlugin.init();
|
||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
|
||||
|
||||
if(device.platform != "Android"){
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
}else{
|
||||
window.plugins.jPushPlugin.setDebugMode(true);
|
||||
}
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
$("#setTagWithAliasButton").click(function(ev) {
|
||||
try{
|
||||
var tag1 = $("#tagText1").attr("value");
|
||||
var tag2 = $("#tagText2").attr("value");
|
||||
var tag3 = $("#tagText3").attr("value");
|
||||
var alias = $("#aliasText").attr("value");
|
||||
var dd = [];
|
||||
|
||||
if(tag1==""&&tag2==""&&tag3==""){
|
||||
}
|
||||
else{
|
||||
if(tag1 != ""){
|
||||
dd.push(tag1);
|
||||
}
|
||||
if(tag2 != ""){
|
||||
dd.push(tag2);
|
||||
}
|
||||
if(tag3 != ""){
|
||||
dd.push(tag3);
|
||||
}
|
||||
}
|
||||
window.plugins.jPushPlugin.setTagsWithAlias(dd,alias);
|
||||
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
})
|
||||
}
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
})
|
||||
};
|
||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||
document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
|
||||
|
||||
|
||||
//jpush.receiveMessage
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div data-role="page" id="page">
|
||||
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
|
||||
<div data-role="fieldcontain">
|
||||
<center><h3>JPushPlugin Example</h3></center>
|
||||
<span name="alias" id="alias"></span><hr />
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationid">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias" />
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt" >设置tag/alias结果: </label>
|
||||
<label id="tagAliasResult" >null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt" >接受的通知内容:</label>
|
||||
<label id="notificationResult" >null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt" >接受的自定义消息:</label>
|
||||
<label id="messageResult" >null</label>
|
||||
</div>
|
||||
//jpush.receiveMessage
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div data-role="page" id="page">
|
||||
|
||||
<div data-role="content">
|
||||
<form>
|
||||
<div class="ui-body ui-body-b">
|
||||
|
||||
<div data-role="fieldcontain">
|
||||
<center><h3>JPushPlugin Example</h3></center>
|
||||
<span name="alias" id="alias"></span>
|
||||
<hr/>
|
||||
<label>RegistrationID: </label>
|
||||
<label id="registrationid">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label>Tags: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText1"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText2"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="tagText3">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<label>Alias: </label>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" id="aliasText">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<input type="button" id="setTagWithAliasButton" value="Add tag and alias"/>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="tagAliasPrompt">设置tag/alias结果: </label>
|
||||
<label id="tagAliasResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="notificationPrompt">接受的通知内容:</label>
|
||||
<label id="notificationResult">null</label>
|
||||
</div>
|
||||
<div data-role="fieldcontain">
|
||||
<label id="messagePrompt">接受的自定义消息:</label>
|
||||
<label id="messageResult">null</label>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
47
plugin.xml
47
plugin.xml
@@ -2,7 +2,7 @@
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cn.jpush.phonegap.JPushPlugin"
|
||||
version="2.0.2">
|
||||
version="2.1.0">
|
||||
|
||||
<name>JPush Plugin</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
@@ -10,12 +10,14 @@
|
||||
<keywords>JPush,push</keywords>
|
||||
<license>Apache 2.0 License</license>
|
||||
|
||||
<preference name="API_KEY" />
|
||||
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.0"/>
|
||||
</engines>
|
||||
|
||||
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
|
||||
<clobbers target="window.plugins.jPushPlugin"/>
|
||||
<clobbers target="jPushPlugin"/>
|
||||
</js-module>
|
||||
|
||||
<platform name="ios">
|
||||
@@ -27,12 +29,12 @@
|
||||
|
||||
<header-file src="src/ios/Plugins/JPushPlugin.h"/>
|
||||
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
|
||||
|
||||
<header-file src="src/ios/lib/APService.h" />
|
||||
<source-file src="src/ios/lib/libPushSDK-1.8.3.a" framework="true" />
|
||||
|
||||
|
||||
<header-file src="src/ios/lib/JPUSHService.h" />
|
||||
<source-file src="src/ios/lib/jpush-ios-2.1.0.a" framework="true" />
|
||||
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
|
||||
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
|
||||
<resource-file src="src/ios/PushConfig.plist" />
|
||||
|
||||
<framework src="CFNetwork.framework" weak="true" />
|
||||
<framework src="CoreFoundation.framework" weak="true" />
|
||||
<framework src="CoreTelephony.framework" weak="true" />
|
||||
@@ -42,12 +44,19 @@
|
||||
<framework src="UIKit.framework" weak="true" />
|
||||
<framework src="Security.framework" weak="true" />
|
||||
<framework src="libz.dylib" weak="true" />
|
||||
|
||||
|
||||
<config-file target="*PushConfig.plist" parent="APP_KEY">
|
||||
<string>$API_KEY</string>
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
|
||||
<hook type="after_plugin_add" src="scripts/android-install.js" />
|
||||
<hook type="after_plugin_install" src="scripts/android-install.js" />
|
||||
<hook type="before_plugin_rm" src="scripts/android-install.js" />
|
||||
<hook type="before_plugin_uninstall" src="scripts/android-install.js" />
|
||||
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="JPushPlugin">
|
||||
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin"/>
|
||||
@@ -152,16 +161,18 @@
|
||||
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
|
||||
<!-- Required . Enable it you can get statistics data with channel -->
|
||||
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
|
||||
</config-file>
|
||||
<source-file src="src/android/jpush-sdk-release1.7.5.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush175.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush175.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush175.so" target-dir="libs/armeabi-v8a"/>
|
||||
|
||||
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
|
||||
<source-file src="src/android/jpush-android-2.1.0.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush210.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush210.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush210.so" target-dir="libs/arm64-v8a"/>
|
||||
<source-file src="src/android/x86/libjpush210.so" target-dir="libs/x86"/>
|
||||
<source-file src="src/android/x86_64/libjpush210.so" target-dir="libs/x86_64"/>
|
||||
|
||||
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
|
||||
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
|
||||
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
|
||||
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable"/>
|
||||
</platform>
|
||||
</plugin>
|
||||
</plugin>
|
||||
|
||||
48
scripts/android-install.js
Normal file
48
scripts/android-install.js
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
module.exports = function (context) {
|
||||
var path = context.requireCordovaModule('path'),
|
||||
fs = context.requireCordovaModule('fs'),
|
||||
shell = context.requireCordovaModule('shelljs'),
|
||||
projectRoot = context.opts.projectRoot,
|
||||
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
|
||||
config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
|
||||
packageName = config.android_packageName() || config.packageName();
|
||||
|
||||
console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + ".");
|
||||
|
||||
if (!packageName) {
|
||||
console.error("Package name could not be found!");
|
||||
return ;
|
||||
}
|
||||
|
||||
// android platform available?
|
||||
if (context.opts.cordova.platforms.indexOf("android") === -1) {
|
||||
console.info("Android platform has not been added.");
|
||||
return ;
|
||||
}
|
||||
|
||||
var targetDir = path.join(projectRoot, "platforms", "android", "src", "cn", "jpush", "phonegap");
|
||||
targetFile = path.join(targetDir, "JPushPlugin.java");
|
||||
console.log(targetDir);
|
||||
|
||||
if (['after_plugin_add', 'after_plugin_install', 'after_platform_add'].indexOf(context.hook) === -1) {
|
||||
// remove it?
|
||||
try {
|
||||
fs.unlinkSync(targetFile);
|
||||
} catch (err) {}
|
||||
} else {
|
||||
// create directory
|
||||
shell.mkdir('-p', targetDir);
|
||||
|
||||
// sync the content
|
||||
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'), {encoding: 'utf-8'}, function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
|
||||
fs.writeFileSync(targetFile, data);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,14 +1,13 @@
|
||||
package cn.jpush.phonegap;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import __PACKAGE_NAME__.R;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.CordovaInterface;
|
||||
@@ -17,375 +16,382 @@ import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import your.package.name.R;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import cn.jpush.android.api.BasicPushNotificationBuilder;
|
||||
import cn.jpush.android.api.CustomPushNotificationBuilder;
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import cn.jpush.android.data.JPushLocalNotification;
|
||||
import cn.jpush.android.api.TagAliasCallback;
|
||||
import cn.jpush.android.data.JPushLocalNotification;
|
||||
|
||||
public class JPushPlugin extends CordovaPlugin {
|
||||
private final static List<String> methodList =
|
||||
Arrays.asList(
|
||||
"getRegistrationID",
|
||||
"setTags",
|
||||
"setTagsWithAlias",
|
||||
"setAlias",
|
||||
"getNotification",
|
||||
"setBasicPushNotificationBuilder",
|
||||
"setCustomPushNotificationBuilder",
|
||||
"setPushTime",
|
||||
"init",
|
||||
"setDebugMode",
|
||||
"stopPush",
|
||||
"resumePush",
|
||||
"isPushStopped",
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"clearAllNotification",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications",
|
||||
"onResume",
|
||||
"onPause",
|
||||
"reportNotificationOpened");
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
private final static List<String> methodList =
|
||||
Arrays.asList(
|
||||
"getRegistrationID",
|
||||
"setTags",
|
||||
"setTagsWithAlias",
|
||||
"setAlias",
|
||||
"getNotification",
|
||||
"setBasicPushNotificationBuilder",
|
||||
"setCustomPushNotificationBuilder",
|
||||
"setPushTime",
|
||||
"init",
|
||||
"setDebugMode",
|
||||
"stopPush",
|
||||
"resumePush",
|
||||
"isPushStopped",
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"clearAllNotification",
|
||||
"clearNotificationById",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications",
|
||||
"onResume",
|
||||
"onPause",
|
||||
"reportNotificationOpened",
|
||||
"setStatisticsOpen");
|
||||
|
||||
public static String notificationAlert;
|
||||
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
private static Activity cordovaActivity;
|
||||
private static String TAG = "JPushPlugin";
|
||||
|
||||
public JPushPlugin() {
|
||||
instance = this;
|
||||
}
|
||||
private static boolean shouldCacheMsg = false;
|
||||
private static boolean isStatisticsOpened = true; // 是否开启统计分析功能
|
||||
|
||||
@Override
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
//JPushInterface.setDebugMode(true);
|
||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||
}
|
||||
public static String notificationAlert;
|
||||
public static Map<String, Object> notificationExtras = new HashMap<String, Object>();
|
||||
public static String openNotificationAlert;
|
||||
public static Map<String, Object> openNotificationExtras = new HashMap<String, Object>();
|
||||
|
||||
public JPushPlugin() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private static JSONObject notificationObject(String message,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("message", message);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for(Entry<String,Object> entry:extras.entrySet()){
|
||||
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
|
||||
JSONObject jo = new JSONObject((String)entry.getValue());
|
||||
@Override
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
|
||||
Log.i(TAG, "---------------- initialize" + "-"
|
||||
+ JPushPlugin.openNotificationAlert + "-"
|
||||
+ JPushPlugin.notificationAlert);
|
||||
|
||||
cordovaActivity = this.cordova.getActivity();
|
||||
|
||||
//如果同时缓存了打开事件openNotificationAlert 和 消息事件notificationAlert,只向UI 发 打开事件。
|
||||
//这样做是为了和iOS 统一
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
}
|
||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||
}
|
||||
|
||||
public void onPause(boolean multitasking) {
|
||||
Log.i(TAG, "---------------- onPause");
|
||||
shouldCacheMsg = true;
|
||||
if (isStatisticsOpened) {
|
||||
JPushInterface.onPause(cordovaActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume(boolean multitasking) {
|
||||
shouldCacheMsg = false;
|
||||
Log.i(TAG, "---------------- onResume" + "-"
|
||||
+ JPushPlugin.openNotificationAlert + "-"
|
||||
+ JPushPlugin.notificationAlert);
|
||||
if (isStatisticsOpened) {
|
||||
JPushInterface.onResume(cordovaActivity);
|
||||
}
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
}
|
||||
}
|
||||
|
||||
private static JSONObject notificationObject(String message,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("message", message);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(),entry.getValue());
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if(jExtras.length()>0)
|
||||
{
|
||||
data.put("extras", jExtras);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
if (jExtras.length() > 0) {
|
||||
data.put("extras", jExtras);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
private static JSONObject openNotificationObject(String alert,
|
||||
Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("alert", alert);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
if (jExtras.length() > 0) {
|
||||
data.put("extras", jExtras);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JSONObject openNotificationObject(String alert,
|
||||
Map<String, Object> extras){
|
||||
JSONObject data = new JSONObject();
|
||||
try{
|
||||
data.put("alert", alert);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for(Entry<String,Object> entry:extras.entrySet()){
|
||||
if(entry.getKey().equals("cn.jpush.android.EXTRA")){
|
||||
JSONObject jo = new JSONObject((String)entry.getValue());
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
}else{
|
||||
jExtras.put(entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
if(jExtras.length()>0)
|
||||
{
|
||||
data.put("extras", jExtras);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
static void transmitPush(String message, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = notificationObject(message, extras);
|
||||
String format = "window.plugins.jPushPlugin.receiveMessageInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
static void transmitPush(String message, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = notificationObject(message, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.receiveMessageInAndroidCallback('%s');",
|
||||
data.toString());
|
||||
|
||||
|
||||
try {
|
||||
instance.webView.sendJavascript(js);
|
||||
|
||||
// String jsEvent=String
|
||||
// .format("cordova.fireDocumentEvent('jpush.receiveMessage',%s)",
|
||||
// data.toString());
|
||||
// instance.webView.sendJavascript(jsEvent);
|
||||
} catch (NullPointerException e) {
|
||||
static void transmitOpen(String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
if (JPushPlugin.shouldCacheMsg) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.openNotificationAlert = null;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.notificationAlert = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
static void transmitOpen(String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.openNotificationInAndroidCallback('%s');",
|
||||
data.toString());
|
||||
// {"alert":"ding",
|
||||
// "extras":{
|
||||
// "cn.jpush.android.MSG_ID":"1691785879",
|
||||
// "app":"com.thi.pushtest",
|
||||
// "cn.jpush.android.ALERT":"ding",
|
||||
// "cn.jpush.android.EXTRA":{},
|
||||
// "cn.jpush.android.PUSH_ID":"1691785879",
|
||||
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
try {
|
||||
instance.webView.sendJavascript(js);
|
||||
|
||||
// String jsEvent=String
|
||||
// .format("cordova.fireDocumentEvent('jpush.openNotification',%s)",
|
||||
// data.toString());
|
||||
// instance.webView.sendJavascript(jsEvent);
|
||||
} catch (NullPointerException e) {
|
||||
@Override
|
||||
public boolean execute(final String action, final JSONArray data,
|
||||
final CallbackContext callbackContext) throws JSONException {
|
||||
if (!methodList.contains(action)) {
|
||||
return false;
|
||||
}
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Method method = JPushPlugin.class.getDeclaredMethod(action,
|
||||
JSONArray.class, CallbackContext.class);
|
||||
method.invoke(JPushPlugin.this, data, callbackContext);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
void init(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.init(cordovaActivity.getApplicationContext());
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
String js = String
|
||||
.format("window.plugins.jPushPlugin.receiveNotificationInAndroidCallback('%s');",
|
||||
data.toString());
|
||||
// {"alert":"ding",
|
||||
// "extras":{
|
||||
// "cn.jpush.android.MSG_ID":"1691785879",
|
||||
// "app":"com.thi.pushtest",
|
||||
// "cn.jpush.android.ALERT":"ding",
|
||||
// "cn.jpush.android.EXTRA":{},
|
||||
// "cn.jpush.android.PUSH_ID":"1691785879",
|
||||
// "cn.jpush.android.NOTIFICATION_ID":1691785879,
|
||||
// "cn.jpush.android.NOTIFICATION_TYPE":"0"}}
|
||||
try {
|
||||
|
||||
instance.webView.sendJavascript(js);
|
||||
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||
boolean mode;
|
||||
try {
|
||||
mode = data.getBoolean(0);
|
||||
JPushInterface.setDebugMode(mode);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (NullPointerException e) {
|
||||
void stopPush(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.stopPush(cordovaActivity.getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
void resumePush(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.resumePush(cordovaActivity.getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
void isPushStopped(JSONArray data, CallbackContext callbackContext) {
|
||||
boolean isStopped = JPushInterface.isPushStopped(
|
||||
cordovaActivity.getApplicationContext());
|
||||
if (isStopped) {
|
||||
callbackContext.success(1);
|
||||
} else {
|
||||
callbackContext.success(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final String action, final JSONArray data,
|
||||
final CallbackContext callbackContext) throws JSONException {
|
||||
if (!methodList.contains(action)) {
|
||||
return false;
|
||||
}
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Method method = JPushPlugin.class.getDeclaredMethod(action,
|
||||
JSONArray.class, CallbackContext.class);
|
||||
method.invoke(JPushPlugin.this, data, callbackContext);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void init(JSONArray data,CallbackContext callbackContext){
|
||||
JPushInterface.init(this.cordova.getActivity().getApplicationContext());
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
|
||||
boolean mode;
|
||||
try {
|
||||
mode = data.getBoolean(0);
|
||||
// if (mode.equals("true")) {
|
||||
// JPushInterface.setDebugMode(true);
|
||||
// } else if (mode.equals("false")) {
|
||||
// JPushInterface.setDebugMode(false);
|
||||
// } else {
|
||||
// callbackContext.error("error mode");
|
||||
// }
|
||||
JPushInterface.setDebugMode(mode);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
||||
void stopPush(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
JPushInterface.stopPush(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void resumePush(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
JPushInterface.resumePush(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void isPushStopped(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
boolean isStopped =JPushInterface.isPushStopped(this.cordova.getActivity().getApplicationContext());
|
||||
if(isStopped){
|
||||
callbackContext.success(1);
|
||||
}else{
|
||||
callbackContext.success(0);
|
||||
}
|
||||
}
|
||||
|
||||
void setLatestNotificationNum(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
int num = -1;
|
||||
try {
|
||||
num = data.getInt(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading num json");
|
||||
}
|
||||
if(num != -1){
|
||||
JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num);
|
||||
}else{
|
||||
callbackContext.error("error num");
|
||||
}
|
||||
}
|
||||
|
||||
void setPushTime(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
Set<Integer> days = new HashSet<Integer>();
|
||||
JSONArray dayArray;
|
||||
int startHour = -1;
|
||||
int endHour = -1;
|
||||
try {
|
||||
dayArray = data.getJSONArray(0);
|
||||
for (int i = 0; i < dayArray.length(); i++) {
|
||||
days.add(dayArray.getInt(i));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading days json");
|
||||
}
|
||||
try{
|
||||
startHour = data.getInt(1);
|
||||
endHour = data.getInt(2);
|
||||
}catch(JSONException e){
|
||||
callbackContext.error("error reading hour json");
|
||||
}
|
||||
JPushInterface.setPushTime(this.cordova.getActivity().getApplicationContext(), days, startHour, endHour);
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
void getRegistrationID(JSONArray data, CallbackContext callbackContext) {
|
||||
String regID= JPushInterface.getRegistrationID(this.cordova.getActivity().getApplicationContext());
|
||||
callbackContext.success(regID);
|
||||
void setLatestNotificationNum(JSONArray data, CallbackContext callbackContext) {
|
||||
int num = -1;
|
||||
try {
|
||||
num = data.getInt(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading num json");
|
||||
}
|
||||
if (num != -1) {
|
||||
JPushInterface.setLatestNotificationNumber(
|
||||
cordovaActivity.getApplicationContext(), num);
|
||||
} else {
|
||||
callbackContext.error("error num");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void onResume(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onResume(this.cordova.getActivity());
|
||||
}
|
||||
void onPause(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onPause(this.cordova.getActivity());
|
||||
}
|
||||
void reportNotificationOpened(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String msgID;
|
||||
msgID = data.getString(0);
|
||||
JPushInterface.reportNotificationOpened(this.cordova.getActivity(),msgID);
|
||||
} catch (JSONException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
void setPushTime(JSONArray data, CallbackContext callbackContext) {
|
||||
Set<Integer> days = new HashSet<Integer>();
|
||||
JSONArray dayArray;
|
||||
int startHour = -1;
|
||||
int endHour = -1;
|
||||
try {
|
||||
dayArray = data.getJSONArray(0);
|
||||
for (int i = 0; i < dayArray.length(); i++) {
|
||||
days.add(dayArray.getInt(i));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading days json");
|
||||
}
|
||||
try {
|
||||
startHour = data.getInt(1);
|
||||
endHour = data.getInt(2);
|
||||
} catch (JSONException e) {
|
||||
callbackContext.error("error reading hour json");
|
||||
}
|
||||
Context context = cordovaActivity.getApplicationContext();
|
||||
JPushInterface.setPushTime(context, days, startHour, endHour);
|
||||
callbackContext.success();
|
||||
}
|
||||
|
||||
}
|
||||
void setTags(JSONArray data, CallbackContext callbackContext) {
|
||||
void getRegistrationID(JSONArray data, CallbackContext callbackContext) {
|
||||
Context context = cordovaActivity.getApplicationContext();
|
||||
String regID = JPushInterface.getRegistrationID(context);
|
||||
callbackContext.success(regID);
|
||||
}
|
||||
|
||||
HashSet<String> tags=null;
|
||||
try {
|
||||
String tagStr;
|
||||
if(data==null){
|
||||
//tags=null;
|
||||
}else if(data.length()==0) {
|
||||
tags= new HashSet<String>();
|
||||
}else{
|
||||
tagStr = data.getString(0);
|
||||
String[] tagArray = tagStr.split(",");
|
||||
for (String tag : tagArray) {
|
||||
if(tags==null){
|
||||
tags= new HashSet<String>();
|
||||
}
|
||||
tags.add(tag);
|
||||
}
|
||||
}
|
||||
//Set<String> validTags = JPushInterface.filterValidTags(tags);
|
||||
JPushInterface.setTags(this.cordova.getActivity()
|
||||
.getApplicationContext(), tags,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading tags JSON");
|
||||
}
|
||||
}
|
||||
void onResume(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onResume(cordovaActivity);
|
||||
}
|
||||
|
||||
void setAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String alias = data.getString(0);
|
||||
JPushInterface.setAlias(this.cordova.getActivity()
|
||||
.getApplicationContext(), alias,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading alias JSON");
|
||||
}
|
||||
}
|
||||
void onPause(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.onPause(cordovaActivity);
|
||||
}
|
||||
|
||||
void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
HashSet<String> tags = new HashSet<String>();
|
||||
String alias;
|
||||
try {
|
||||
alias = data.getString(0);
|
||||
JSONArray tagsArray = data.getJSONArray(1);
|
||||
for (int i = 0; i < tagsArray.length(); i++) {
|
||||
tags.add(tagsArray.getString(i));
|
||||
}
|
||||
void reportNotificationOpened(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String msgID;
|
||||
msgID = data.getString(0);
|
||||
JPushInterface.reportNotificationOpened(cordovaActivity, msgID);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
JPushInterface.setAliasAndTags(this.cordova.getActivity()
|
||||
.getApplicationContext(), alias, tags,mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading tagAlias JSON");
|
||||
}
|
||||
}
|
||||
void setTags(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
HashSet<String> tags = new HashSet<String>();
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
tags.add(data.getString(i));
|
||||
}
|
||||
JPushInterface.setTags(cordovaActivity.getApplicationContext(),
|
||||
tags, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading tags JSON");
|
||||
}
|
||||
}
|
||||
|
||||
void setAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
String alias = data.getString(0);
|
||||
JPushInterface.setAlias(cordovaActivity.getApplicationContext(),
|
||||
alias, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading alias JSON");
|
||||
}
|
||||
}
|
||||
|
||||
void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
|
||||
HashSet<String> tags = new HashSet<String>();
|
||||
String alias;
|
||||
try {
|
||||
alias = data.getString(0);
|
||||
JSONArray tagsArray = data.getJSONArray(1);
|
||||
for (int i = 0; i < tagsArray.length(); i++) {
|
||||
tags.add(tagsArray.getString(i));
|
||||
}
|
||||
JPushInterface.setAliasAndTags(cordovaActivity.getApplicationContext(),
|
||||
alias, tags, mTagWithAliasCallback);
|
||||
callbackContext.success();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("Error reading tagAlias JSON");
|
||||
}
|
||||
}
|
||||
|
||||
// void getNotification(JSONArray data, CallbackContext callBackContext) {
|
||||
// String alert = JPushPlugin.notificationAlert;
|
||||
@@ -405,123 +411,126 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
// JPushPlugin.notificationExtras = new HashMap<String, Obl>();
|
||||
// }
|
||||
|
||||
void setBasicPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||
this.cordova.getActivity());
|
||||
builder.developerArg0 = "Basic builder 1";
|
||||
JPushInterface.setPushNotificationBuilder(1, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("id", 1);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
void setBasicPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
|
||||
cordovaActivity);
|
||||
builder.developerArg0 = "Basic builder 1";
|
||||
JPushInterface.setPushNotificationBuilder(1, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("id", 1);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
|
||||
void setCustomPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||
this.cordova.getActivity(), R.layout.test_notification_layout,
|
||||
R.id.icon, R.id.title, R.id.text);
|
||||
builder.developerArg0 = "Custom Builder 1";
|
||||
builder.layoutIconDrawable = R.drawable.jpush_notification_icon;
|
||||
JPushInterface.setPushNotificationBuilder(2, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("id", 2);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
|
||||
void clearAllNotification(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
JPushInterface.clearAllNotifications(this.cordova.getActivity());
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
void clearNotificationById(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
int notificationId=-1;
|
||||
try {
|
||||
notificationId = data.getInt(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading id json");
|
||||
}
|
||||
if(notificationId != -1){
|
||||
JPushInterface.clearNotificationById(this.cordova.getActivity(), notificationId);
|
||||
}else{
|
||||
callbackContext.error("error id");
|
||||
}
|
||||
}
|
||||
void addLocalNotification(JSONArray data,
|
||||
CallbackContext callbackContext) throws JSONException{
|
||||
//builderId,content,title,notificaitonID,broadcastTime,extras
|
||||
|
||||
int builderId=data.getInt(0);
|
||||
String content =data.getString(1);
|
||||
String title = data.getString(2);
|
||||
int notificationID= data.getInt(3);
|
||||
int broadcastTime=data.getInt(4);
|
||||
JSONObject extras=data.getJSONObject(5);
|
||||
|
||||
JPushLocalNotification ln = new JPushLocalNotification();
|
||||
ln.setBuilderId(builderId);
|
||||
ln.setContent(content);
|
||||
ln.setTitle(title);
|
||||
ln.setNotificationId(notificationID) ;
|
||||
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
|
||||
void setCustomPushNotificationBuilder(JSONArray data,
|
||||
CallbackContext callbackContext) {
|
||||
CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||
cordovaActivity, R.layout.test_notification_layout,
|
||||
R.id.icon, R.id.title, R.id.text);
|
||||
builder.developerArg0 = "Custom Builder 1";
|
||||
builder.layoutIconDrawable = R.drawable.jpush_notification_icon;
|
||||
JPushInterface.setPushNotificationBuilder(2, builder);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("id", 2);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//callbackContext.success(obj);
|
||||
}
|
||||
|
||||
ln.setExtras(extras.toString()) ;
|
||||
JPushInterface.addLocalNotification(this.cordova.getActivity(), ln);
|
||||
|
||||
}
|
||||
void removeLocalNotification(JSONArray data,
|
||||
CallbackContext callbackContext) throws JSONException{
|
||||
|
||||
int notificationID=data.getInt(0);
|
||||
JPushInterface.removeLocalNotification(this.cordova.getActivity(),notificationID);
|
||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.clearAllNotifications(cordovaActivity);
|
||||
//callbackContext.success();
|
||||
}
|
||||
|
||||
}
|
||||
void clearLocalNotifications(JSONArray data,
|
||||
CallbackContext callbackContext){
|
||||
|
||||
JPushInterface.clearLocalNotifications(this.cordova.getActivity());
|
||||
void clearNotificationById(JSONArray data, CallbackContext callbackContext) {
|
||||
int notificationId = -1;
|
||||
try {
|
||||
notificationId = data.getInt(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
callbackContext.error("error reading id json");
|
||||
}
|
||||
if (notificationId != -1) {
|
||||
JPushInterface.clearNotificationById(cordovaActivity, notificationId);
|
||||
} else {
|
||||
callbackContext.error("error id");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||
void addLocalNotification(JSONArray data, CallbackContext callbackContext)
|
||||
throws JSONException {
|
||||
//builderId,content,title,notificaitonID,broadcastTime,extras
|
||||
int builderId = data.getInt(0);
|
||||
String content = data.getString(1);
|
||||
String title = data.getString(2);
|
||||
int notificationID = data.getInt(3);
|
||||
int broadcastTime = data.getInt(4);
|
||||
JSONObject extras = data.getJSONObject(5);
|
||||
|
||||
JPushLocalNotification ln = new JPushLocalNotification();
|
||||
ln.setBuilderId(builderId);
|
||||
ln.setContent(content);
|
||||
ln.setTitle(title);
|
||||
ln.setNotificationId(notificationID);
|
||||
ln.setBroadcastTime(System.currentTimeMillis() + broadcastTime);
|
||||
|
||||
ln.setExtras(extras.toString());
|
||||
JPushInterface.addLocalNotification(cordovaActivity, ln);
|
||||
}
|
||||
|
||||
void removeLocalNotification(JSONArray data, CallbackContext callbackContext)
|
||||
throws JSONException {
|
||||
int notificationID = data.getInt(0);
|
||||
JPushInterface.removeLocalNotification(cordovaActivity, notificationID);
|
||||
}
|
||||
|
||||
void clearLocalNotifications(JSONArray data, CallbackContext callbackContext) {
|
||||
JPushInterface.clearLocalNotifications(cordovaActivity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 决定是否启用统计分析功能。
|
||||
* @param data
|
||||
* @param callbackContext
|
||||
*/
|
||||
void setStatisticsOpen(JSONArray data, CallbackContext callbackContext) {
|
||||
try {
|
||||
isStatisticsOpened = data.getBoolean(0);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private final TagAliasCallback mTagWithAliasCallback = new TagAliasCallback() {
|
||||
@Override
|
||||
public void gotResult(int code, String alias, Set<String> tags) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("resultCode", code);
|
||||
data.put("tags", tags);
|
||||
data.put("alias", alias);
|
||||
|
||||
String jsEvent=String
|
||||
.format("cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
||||
data.toString());
|
||||
instance.webView.sendJavascript(jsEvent);
|
||||
|
||||
|
||||
} catch (JSONException e) {
|
||||
|
||||
}
|
||||
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("resultCode", code);
|
||||
data.put("tags", tags);
|
||||
data.put("alias", alias);
|
||||
final String jsEvent = String.format(
|
||||
"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%s)",
|
||||
data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.webView.loadUrl("javascript:" + jsEvent);
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,78 +12,82 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
public class MyReceiver extends BroadcastReceiver {
|
||||
private static String TAG = "Client Receiver";
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
private static String TAG = "JPushPlugin";
|
||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||
Arrays.asList(
|
||||
"cn.jpush.android.TITLE",
|
||||
"cn.jpush.android.MESSAGE",
|
||||
"cn.jpush.android.APPKEY",
|
||||
"cn.jpush.android.NOTIFICATION_CONTENT_TITLE"
|
||||
);
|
||||
|
||||
if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
|
||||
|
||||
}else if (JPushInterface.ACTION_UNREGISTER.equals(intent.getAction())){
|
||||
|
||||
} else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
|
||||
handlingReceivedMessage(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
|
||||
handlingNotificationReceive(context,intent);
|
||||
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
|
||||
handlingNotificationOpen(context,intent);
|
||||
} else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(action)) {
|
||||
handlingReceivedMessage(intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(action)) {
|
||||
handlingNotificationReceive(context, intent);
|
||||
} else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(action)) {
|
||||
handlingNotificationOpen(context, intent);
|
||||
} else {
|
||||
Log.d(TAG, "Unhandled intent - " + intent.getAction());
|
||||
Log.d(TAG, "Unhandled intent - " + action);
|
||||
}
|
||||
|
||||
}
|
||||
private void handlingReceivedMessage(Intent intent) {
|
||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
|
||||
JPushPlugin.transmitPush(msg, extras);
|
||||
}
|
||||
private void handlingNotificationOpen(Context context,Intent intent){
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
}
|
||||
|
||||
private void handlingReceivedMessage(Intent intent) {
|
||||
String msg = intent.getStringExtra(JPushInterface.EXTRA_MESSAGE);
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.transmitPush(msg, extras);
|
||||
}
|
||||
|
||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(launch);
|
||||
}
|
||||
|
||||
private void handlingNotificationReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitReceive(alert, extras);
|
||||
}
|
||||
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
for (String key : intent.getExtras().keySet()) {
|
||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||
Log.e("key", "key:" + key);
|
||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
|
||||
extrasMap.put(key, intent.getIntExtra(key, 0));
|
||||
} else {
|
||||
extrasMap.put(key, intent.getStringExtra(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return extrasMap;
|
||||
}
|
||||
|
||||
context.startActivity(launch);
|
||||
}
|
||||
private void handlingNotificationReceive(Context context,Intent intent){
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
Map<String,Object> extras = getNotificationExtras(intent);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitReceive(alert, extras);
|
||||
}
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
Map<String, Object> extrasMap = new HashMap<String, Object>();
|
||||
|
||||
for (String key : intent.getExtras().keySet()) {
|
||||
if (!IGNORED_EXTRAS_KEYS.contains(key)) {
|
||||
Log.e("key","key:"+key);
|
||||
if (key.equals(JPushInterface.EXTRA_NOTIFICATION_ID)){
|
||||
extrasMap.put(key, intent.getIntExtra(key,0));
|
||||
}else{
|
||||
extrasMap.put(key, intent.getStringExtra(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return extrasMap;
|
||||
}
|
||||
private static final List<String> IGNORED_EXTRAS_KEYS =
|
||||
Arrays.asList("cn.jpush.android.TITLE","cn.jpush.android.MESSAGE","cn.jpush.android.APPKEY","cn.jpush.android.NOTIFICATION_CONTENT_TITLE");
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
src/android/arm64-v8a/libjpush210.so
Normal file
BIN
src/android/arm64-v8a/libjpush210.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/armeabi-v7a/libjpush210.so
Normal file
BIN
src/android/armeabi-v7a/libjpush210.so
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/armeabi/libjpush210.so
Normal file
BIN
src/android/armeabi/libjpush210.so
Normal file
Binary file not shown.
BIN
src/android/jpush-android-2.1.0.jar
Normal file
BIN
src/android/jpush-android-2.1.0.jar
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/android/x86/libjpush210.so
Normal file
BIN
src/android/x86/libjpush210.so
Normal file
Binary file not shown.
BIN
src/android/x86_64/libjpush210.so
Normal file
BIN
src/android/x86_64/libjpush210.so
Normal file
Binary file not shown.
13
src/ios/Plugins/AppDelegate+JPush.h
Normal file
13
src/ios/Plugins/AppDelegate+JPush.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// AppDelegate+JPush.h
|
||||
// delegateExtention
|
||||
//
|
||||
// Created by 张庆贺 on 15/8/3.
|
||||
// Copyright (c) 2015年 JPush. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface AppDelegate (JPush)
|
||||
|
||||
@end
|
||||
66
src/ios/Plugins/AppDelegate+JPush.m
Normal file
66
src/ios/Plugins/AppDelegate+JPush.m
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// AppDelegate+JPush.m
|
||||
// delegateExtention
|
||||
//
|
||||
// Created by 张庆贺 on 15/8/3.
|
||||
// Copyright (c) 2015年 JPush. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate+JPush.h"
|
||||
#import "JPushPlugin.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@implementation AppDelegate (JPush)
|
||||
|
||||
+(void)load{
|
||||
Method origin;
|
||||
Method swizzle;
|
||||
origin=class_getInstanceMethod([self class],@selector(init));
|
||||
swizzle=class_getInstanceMethod([self class], @selector(init_plus));
|
||||
method_exchangeImplementations(origin, swizzle);
|
||||
}
|
||||
|
||||
-(instancetype)init_plus{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(applicationDidLaunch:)
|
||||
name:@"UIApplicationDidFinishLaunchingNotification"
|
||||
object:nil];
|
||||
return [self init_plus];
|
||||
}
|
||||
|
||||
-(void)applicationDidLaunch:(NSNotification*)notification{
|
||||
if (notification) {
|
||||
[JPushPlugin setLaunchOptions:notification.userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
[JPUSHService registerDeviceToken:deviceToken];
|
||||
}
|
||||
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
|
||||
}
|
||||
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification object:userInfo];
|
||||
completionHandler(UIBackgroundFetchResultNewData);
|
||||
}
|
||||
|
||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
||||
[JPUSHService showLocalNotificationAtFront:notification identifierKey:nil];
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
// [application setApplicationIconBadgeNumber:0];
|
||||
// [application cancelAllLocalNotifications];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
// [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,15 +11,59 @@
|
||||
#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
|
||||
|
||||
@interface JPushPlugin : CDVPlugin{
|
||||
|
||||
|
||||
}
|
||||
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions;
|
||||
|
||||
//以下为js中可调用接口
|
||||
//设置标签、别名
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setTags:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setAlias:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//获取 RegistrationID
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//页面统计
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//设置角标到服务器,服务器下一次发消息时,会设置成这个值
|
||||
//本接口不会改变应用本地的角标值.
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command;
|
||||
//相当于 [setBadge:0]
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//应用本地的角标值设置/获取
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//停止与恢复推送
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command;
|
||||
-(void)resumePush:(CDVInvokedUrlCommand*)command;
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//开关日志
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command;
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command;
|
||||
-(void)crashLogON:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//本地推送
|
||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command;
|
||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command;
|
||||
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
//地理位置上报 [latitude,longitude]
|
||||
-(void)setLocation:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
/*
|
||||
* 以下为js中可监听到的事件
|
||||
* jpush.openNotification 点击推送消息唤醒或启动app
|
||||
* jpush.setTagsWithAlias 设置标签、别名完成
|
||||
* jpush.receiveMessage 收到自定义消息
|
||||
* jpush.receiveNotification 前台收到推送消息
|
||||
*/
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,336 +7,378 @@
|
||||
//
|
||||
|
||||
#import "JPushPlugin.h"
|
||||
#import "APService.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
static NSDictionary *_luanchOptions=nil;
|
||||
static NSString *const JM_APP_KEY = @"APP_KEY";
|
||||
static NSString *const JM_APP_CHANNEL = @"CHANNEL";
|
||||
static NSString *const JM_APP_ISPRODUCTION = @"IsProduction";
|
||||
static NSString *const JPushConfigFileName = @"PushConfig";
|
||||
static NSDictionary *_luanchOptions = nil;
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
#pragma mark- 外部接口
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
||||
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||
}
|
||||
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_luanchOptions=theLaunchOptions;
|
||||
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||
UIUserNotificationTypeSound |
|
||||
UIUserNotificationTypeAlert)
|
||||
categories:nil];
|
||||
[APService setupWithOption:_luanchOptions];
|
||||
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
||||
[JPushPlugin registerForRemoteNotification];
|
||||
}
|
||||
|
||||
+(void)registerForRemoteNotification{
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
||||
//可以添加自定义categories
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||
UIUserNotificationTypeSound |
|
||||
UIUserNotificationTypeAlert)
|
||||
categories:nil];
|
||||
} else {
|
||||
//categories 必须为nil
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
|
||||
result = @(0);
|
||||
}else{
|
||||
result = @(1);
|
||||
}
|
||||
[self hanleResultWithValue:result command:command];
|
||||
}
|
||||
|
||||
-(void)initial:(CDVInvokedUrlCommand*)command{
|
||||
//do nithng,because Cordova plugin use lazy load mode.
|
||||
|
||||
}
|
||||
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
|
||||
- (void)pluginInitialize {
|
||||
NSLog(@"### pluginInitialize ");
|
||||
[self initNotifications];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||
NSLog(@"### initWithWebView ");
|
||||
if (self=[super initWithWebView:theWebView]) {
|
||||
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveNotification:)
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
if (_luanchOptions) {
|
||||
NSDictionary *userInfo = [_luanchOptions
|
||||
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
if ([userInfo count] >0) {
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
if (!error) {
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[self initNotifications];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",@""]];
|
||||
return ;
|
||||
}
|
||||
NSString *alias=[arguments objectAtIndex:0];
|
||||
NSArray *arrayTags=[arguments objectAtIndex:1];
|
||||
NSSet* set=[NSSet setWithArray:arrayTags];
|
||||
[APService setTags:set
|
||||
alias:alias
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
-(void)resumePush:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
|
||||
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
|
||||
//可以添加自定义categories
|
||||
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||
UIUserNotificationTypeSound |
|
||||
UIUserNotificationTypeAlert)
|
||||
categories:nil];
|
||||
} else {
|
||||
//categories 必须为nil
|
||||
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
}
|
||||
#else
|
||||
//categories 必须为nil
|
||||
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
#endif
|
||||
|
||||
}
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||
-(void)initNotifications {
|
||||
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveMessage:)
|
||||
name:kJPFNetworkDidReceiveMessageNotification
|
||||
object:nil];
|
||||
|
||||
[defaultCenter addObserver:self
|
||||
selector:@selector(networkDidReceiveNotification:)
|
||||
name:kJPushPluginReceiveNotification
|
||||
object:nil];
|
||||
|
||||
if (_luanchOptions) {
|
||||
NSDictionary *userInfo = [_luanchOptions
|
||||
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
||||
if ([userInfo count] >0) {
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
if (!error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
|
||||
result=@(1);
|
||||
}else{
|
||||
result=@(0);
|
||||
}
|
||||
CDVPluginResult * pushResult=[self pluginResultForValue:result];
|
||||
if (pushResult) {
|
||||
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
}}
|
||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
NSString *tags=[arguments objectAtIndex:0];
|
||||
|
||||
NSArray *array=[tags componentsSeparatedByString:@","];
|
||||
[APService setTags:[NSSet setWithArray:array]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
NSString *alias;
|
||||
NSArray *tags;
|
||||
if (!arguments || [arguments count] < 2) {
|
||||
NSLog(@"#### setTagsWithAlias param is less");
|
||||
return ;
|
||||
}else{
|
||||
alias = arguments[0];
|
||||
tags = arguments[1];
|
||||
}
|
||||
|
||||
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,tags);
|
||||
|
||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||
alias:alias
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
NSArray *tags = command.arguments;
|
||||
|
||||
NSLog(@"#### setTags %@",tags);
|
||||
|
||||
[JPUSHService setTags:[NSSet setWithArray:tags]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
}
|
||||
|
||||
-(void)setAlias:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
[APService setAlias:[arguments objectAtIndex:0]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
|
||||
|
||||
NSLog(@"#### setAlias %@",command.arguments);
|
||||
[JPUSHService setAlias:command.arguments[0]
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSString* registrationID = [APService registrationID];
|
||||
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||
if (result) {
|
||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
NSString* registrationID = [JPUSHService registrationID];
|
||||
NSLog(@"### getRegistrationID %@",registrationID);
|
||||
[self hanleResultWithValue:registrationID command:command];
|
||||
}
|
||||
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
if (pageName) {
|
||||
[JPUSHService startLogPageView:pageName];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
||||
|
||||
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:resultCode],@"resultCode",
|
||||
tags==nil?[NSNull null]:[tags allObjects],@"tags",
|
||||
alias==nil?[NSNull null]:alias,@"alias",nil];
|
||||
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
||||
[data setObject:[NSNumber numberWithInt:resultCode] forKey:@"resultCode"];
|
||||
[data setObject:tags==nil?[NSNull null]:[tags allObjects] forKey:@"tags"];
|
||||
[data setObject:alias==nil?[NSNull null]:alias forKey:@"alias"];
|
||||
NSError *error;
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
if (pageName) {
|
||||
[JPUSHService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
if (!arguments || [arguments count] < 2) {
|
||||
NSLog(@"beginLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName = arguments[0];
|
||||
int duration = [arguments[0] intValue];
|
||||
if (pageName) {
|
||||
[JPUSHService beginLogPageView:pageName duration:duration];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *argument = command.arguments;
|
||||
if ([argument count] < 1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge = argument[0];
|
||||
[JPUSHService setBadge:[badge intValue]];
|
||||
}
|
||||
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService resetBadge];
|
||||
}
|
||||
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
|
||||
//
|
||||
NSArray *argument = command.arguments;
|
||||
if ([argument count] < 1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge = [argument objectAtIndex:0];
|
||||
[UIApplication sharedApplication].applicationIconBadgeNumber = [badge intValue];
|
||||
}
|
||||
|
||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
|
||||
NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
|
||||
NSNumber *number = [NSNumber numberWithInteger:num];
|
||||
[self hanleResultWithValue:number command:command];
|
||||
}
|
||||
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService setDebugMode];
|
||||
}
|
||||
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService setLogOFF];
|
||||
}
|
||||
|
||||
-(void)crashLogON:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService crashLogON];
|
||||
}
|
||||
|
||||
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments = command.arguments;
|
||||
NSDate *date = arguments[0] == [NSNull null] ? nil : [NSDate dateWithTimeIntervalSinceNow:[((NSString*)arguments[0]) intValue]];
|
||||
NSString *alertBody = arguments[1] == [NSNull null] ? nil : (NSString*)arguments[1];
|
||||
int badge = arguments[2] == [NSNull null] ? 0 : [(NSString*)arguments[2] intValue];
|
||||
NSString *idKey = arguments[3] == [NSNull null] ? nil : (NSString*)arguments[3];
|
||||
NSDictionary *dict = arguments[4] == [NSNull null] ? nil : (NSDictionary*)arguments[4];
|
||||
[JPUSHService setLocalNotification:date alertBody:alertBody badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
|
||||
}
|
||||
|
||||
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService deleteLocalNotificationWithIdentifierKey:(NSString*)command.arguments[0]];
|
||||
}
|
||||
|
||||
-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService clearAllLocalNotifications];
|
||||
}
|
||||
|
||||
-(void)setLocation:(CDVInvokedUrlCommand*)command{
|
||||
[JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
|
||||
}
|
||||
|
||||
#pragma mark- 内部方法
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_luanchOptions = theLaunchOptions;
|
||||
|
||||
[JPUSHService setDebugMode];
|
||||
|
||||
[JPushPlugin registerForRemoteNotification];
|
||||
|
||||
//read appkey and channel from PushConfig.plist
|
||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfigFileName ofType:@"plist"];
|
||||
if (plistPath == nil) {
|
||||
NSLog(@"error: PushConfig.plist not found");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
|
||||
NSString * appkey = [plistData valueForKey:JM_APP_KEY];
|
||||
NSString * channel = [plistData valueForKey:JM_APP_CHANNEL];
|
||||
NSNumber * isProduction = [plistData valueForKey:JM_APP_ISPRODUCTION];
|
||||
|
||||
if (!appkey || appkey.length == 0) {
|
||||
NSLog(@"error: app key not found in PushConfig.plist ");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
[JPUSHService setupWithOption:_luanchOptions appKey:appkey
|
||||
channel:channel apsForProduction:[isProduction boolValue] ];
|
||||
}
|
||||
|
||||
#pragma mark 将参数返回给js
|
||||
-(void)hanleResultWithValue:(id)value command:(CDVInvokedUrlCommand*)command{
|
||||
CDVPluginResult *result = nil;
|
||||
CDVCommandStatus status = CDVCommandStatus_OK;
|
||||
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
value = [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
} else if ([value isKindOfClass:[NSNull class]]) {
|
||||
value = nil;
|
||||
}
|
||||
|
||||
if ([value isKindOfClass:[NSObject class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:status messageAsString:value];//NSObject 类型都可以
|
||||
} else {
|
||||
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
|
||||
result = nil;
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
}
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
#pragma mark 设置标签及别名回调
|
||||
-(void)tagsWithAliasCallback:(int)resultCode tags:(NSSet *)tags alias:(NSString *)alias{
|
||||
|
||||
NSDictionary *dict = @{@"resultCode":[NSNumber numberWithInt:resultCode],
|
||||
@"tags" :tags == nil ? [NSNull null] : [tags allObjects],
|
||||
@"alias" :alias == nil ? [NSNull null] : alias
|
||||
};
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
||||
// [self writeJavascript:[NSString stringWithFormat:@"window.plugins.jPushPlugin.pushCallback('%@')",jsonString]];
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[APService startLogPageView:pageName];
|
||||
}
|
||||
}
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[APService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
}
|
||||
-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
NSLog(@"beginLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex:0];
|
||||
int duration=[[arguments objectAtIndex:0]intValue];
|
||||
if (pageName) {
|
||||
[APService beginLogPageView:pageName duration:duration];
|
||||
}
|
||||
|
||||
}
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command{
|
||||
NSArray *argument=command.arguments;
|
||||
if ([argument count]<1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge=[argument objectAtIndex:0];
|
||||
[APService setBadge:[badge intValue]];
|
||||
}
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command{
|
||||
[APService resetBadge];
|
||||
}
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[APService setDebugMode];
|
||||
}
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[APService setLogOFF];
|
||||
}
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||
|
||||
}
|
||||
- (void)failWithCallbackID:(NSString *)callbackID {
|
||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||
}
|
||||
- (void)succeedWithPluginResult:(CDVPluginResult *)result withCallbackID:(NSString *)callbackID {
|
||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||
}
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command{
|
||||
//
|
||||
NSArray *argument=command.arguments;
|
||||
if ([argument count]<1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge=[argument objectAtIndex:0];
|
||||
[UIApplication sharedApplication].applicationIconBadgeNumber=[badge intValue];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (CDVPluginResult *)pluginResultForValue:(id)value {
|
||||
|
||||
CDVPluginResult *result;
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
||||
messageAsString:[value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
||||
} else if ([value isKindOfClass:[NSNumber class]]) {
|
||||
CFNumberType numberType = CFNumberGetType((CFNumberRef)value);
|
||||
//note: underlyingly, BOOL values are typedefed as char
|
||||
if (numberType == kCFNumberIntType || numberType == kCFNumberCharType) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:[value intValue]];
|
||||
} else {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:[value doubleValue]];
|
||||
}
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:value];
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:value];
|
||||
} else if ([value isKindOfClass:[NSNull class]]) {
|
||||
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
} else {
|
||||
NSLog(@"Cordova callback block returned unrecognized type: %@", NSStringFromClass([value class]));
|
||||
return nil;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)networkDidReceiveMessage:(NSNotification *)notification {
|
||||
if (notification) {
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
//NSLog(@"%@",userInfo);
|
||||
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
//NSLog(@"%@",userInfo);
|
||||
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
//NSLog(@"%@",jsonString);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||
|
||||
|
||||
});
|
||||
//NSLog(@"%@",jsonString);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",jsonString]];
|
||||
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",jsonString]];
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
-(void)networkDidReceiveNotification:(id)notification{
|
||||
|
||||
|
||||
NSError *error;
|
||||
NSDictionary *userInfo = [notification object];
|
||||
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
NSLog(@"%ld",(long)[UIApplication sharedApplication].applicationState);
|
||||
switch ([UIApplication sharedApplication].applicationState) {
|
||||
case UIApplicationStateActive:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
|
||||
});
|
||||
}
|
||||
break;
|
||||
case UIApplicationStateInactive:
|
||||
case UIApplicationStateBackground:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>APP_KEY</key>
|
||||
<string>7d431e42dfa6a6d693ac2d04</string>
|
||||
<string></string>
|
||||
<key>CHANNEL</key>
|
||||
<string>Subscription</string>
|
||||
<key>IsProduction</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
//
|
||||
// APService.h
|
||||
// APService
|
||||
//
|
||||
// Created by JPush on 12-8-15.
|
||||
// Copyright (c) 2012年 HXHG. All rights reserved.
|
||||
// Version: 1.8.3
|
||||
|
||||
@class CLRegion;
|
||||
@class UILocalNotification;
|
||||
|
||||
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
|
||||
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
|
||||
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
|
||||
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
|
||||
extern NSString *const
|
||||
kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
|
||||
extern NSString *const kJPFServiceErrorNotification; // 错误提示
|
||||
|
||||
@class CLLocation;
|
||||
@interface APService : NSObject
|
||||
|
||||
#pragma - mark 基本功能
|
||||
// 以下四个接口是必须调用的
|
||||
+ (void)setupWithOption:(NSDictionary *)launchingOption; // 初始化
|
||||
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
|
||||
categories:(NSSet *)categories; // 注册APNS类型
|
||||
+ (void)registerDeviceToken:(NSData *)deviceToken; // 向服务器上报Device Token
|
||||
+ (void)handleRemoteNotification:(NSDictionary *)
|
||||
remoteInfo; // 处理收到的APNS消息,向服务器上报收到APNS消息
|
||||
|
||||
// 下面的接口是可选的
|
||||
// 设置标签和(或)别名(若参数为nil,则忽略;若是空对象,则清空;详情请参考文档:http://docs.jpush.cn/pages/viewpage.action?pageId=3309913)
|
||||
+ (void)setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
target:(id)theTarget;
|
||||
+ (void)setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
+ (void)setTags:(NSSet *)tags
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
+ (void)setAlias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
// 用于过滤出正确可用的tags,如果总数量超出最大限制则返回最大数量的靠前的可用tags
|
||||
+ (NSSet *)filterValidTags:(NSSet *)tags;
|
||||
|
||||
#pragma - mark 上报日志
|
||||
/**
|
||||
* 记录页面停留时间功能。
|
||||
* startLogPageView和stopLogPageView为自动计算停留时间
|
||||
* beginLogPageView为手动自己输入停留时间
|
||||
*
|
||||
* @param pageName 页面名称
|
||||
* @param seconds 页面停留时间
|
||||
*/
|
||||
+ (void)startLogPageView:(NSString *)pageName;
|
||||
+ (void)stopLogPageView:(NSString *)pageName;
|
||||
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
|
||||
|
||||
/**
|
||||
* 开启Crash日志收集, 默认是关闭状态.
|
||||
*/
|
||||
+ (void)crashLogON;
|
||||
|
||||
/**
|
||||
* 地理位置设置
|
||||
* 为了更精确的统计用户地理位置,可以调用此方法传入经纬度信息
|
||||
* 需要链接 CoreLocation.framework 并且 #import <CoreLocation/CoreLocation.h>
|
||||
* @param latitude 纬度.
|
||||
* @param longitude 经度.
|
||||
* @param location 直接传递CLLocation *型的地理信息
|
||||
*/
|
||||
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
|
||||
+ (void)setLocation:(CLLocation *)location;
|
||||
|
||||
#pragma - mark 本地通知
|
||||
/**
|
||||
* 本地推送,最多支持64个
|
||||
* @param fireDate 本地推送触发的时间
|
||||
* @param alertBody 本地推送需要显示的内容
|
||||
* @param badge 角标的数字。如果不需要改变角标传-1
|
||||
* @param alertAction 弹框的按钮显示的内容(IOS 8默认为"打开",其他默认为"启动")
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
|
||||
* @param soundName 自定义通知声音,设置为nil为默认声音
|
||||
|
||||
* IOS8新参数
|
||||
* @param region 自定义参数
|
||||
* @param regionTriggersOnce 自定义参数
|
||||
* @param category 自定义参数
|
||||
*/
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
badge:(int)badge
|
||||
alertAction:(NSString *)alertAction
|
||||
identifierKey:(NSString *)notificationKey
|
||||
userInfo:(NSDictionary *)userInfo
|
||||
soundName:(NSString *)soundName;
|
||||
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
badge:(int)badge
|
||||
alertAction:(NSString *)alertAction
|
||||
identifierKey:(NSString *)notificationKey
|
||||
userInfo:(NSDictionary *)userInfo
|
||||
soundName:(NSString *)soundName
|
||||
region:(CLRegion *)region
|
||||
regionTriggersOnce:(BOOL)regionTriggersOnce
|
||||
category:(NSString *)category
|
||||
NS_AVAILABLE_IOS(8_0);
|
||||
|
||||
/**
|
||||
* 本地推送在前台推送。默认App在前台运行时不会进行弹窗,在程序接收通知调用此接口可实现指定的推送弹窗。
|
||||
* @param notification 本地推送对象
|
||||
* @param notificationKey 需要前台显示的本地推送通知的标示符
|
||||
*/
|
||||
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
|
||||
identifierKey:(NSString *)notificationKey;
|
||||
/**
|
||||
* 删除本地推送
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @param myUILocalNotification 本地推送对象
|
||||
*/
|
||||
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
|
||||
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
|
||||
|
||||
/**
|
||||
* 获取指定通知
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @return 本地推送对象数组,[array count]为0时表示没找到
|
||||
*/
|
||||
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
|
||||
|
||||
/**
|
||||
* 清除所有本地推送对象
|
||||
*/
|
||||
+ (void)clearAllLocalNotifications;
|
||||
|
||||
#pragma - mark 设置Badge
|
||||
/**
|
||||
* set setBadge
|
||||
* @param value 设置JPush服务器的badge的值
|
||||
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
|
||||
*/
|
||||
+ (BOOL)setBadge:(NSInteger)value;
|
||||
/**
|
||||
* set setBadge
|
||||
* @param value 清除JPush服务器对badge值的设定.
|
||||
* 本地仍须调用UIApplication:setApplicationIconBadgeNumber函数,来设置脚标
|
||||
*/
|
||||
|
||||
+ (void)resetBadge;
|
||||
|
||||
/**
|
||||
* get RegistrationID
|
||||
*/
|
||||
+ (NSString *)registrationID;
|
||||
|
||||
#pragma - mark 打印日志信息配置
|
||||
/**
|
||||
* setDebugMode获取更多的Log信息
|
||||
* 开发过程中建议开启DebugMode
|
||||
*
|
||||
* setLogOFF关闭除了错误信息外的所有Log
|
||||
* 发布时建议开启LogOFF用于节省性能开销
|
||||
*
|
||||
* 默认为不开启DebugLog,只显示基本的信息
|
||||
*/
|
||||
+ (void)setDebugMode;
|
||||
+ (void)setLogOFF;
|
||||
@end
|
||||
337
src/ios/lib/JPUSHService.h
Executable file
337
src/ios/lib/JPUSHService.h
Executable file
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* | | | | \ \ / / | | | | / _______|
|
||||
* | |____| | \ \/ / | |____| | / /
|
||||
* | |____| | \ / | |____| | | | _____
|
||||
* | | | | / \ | | | | | | |____ |
|
||||
* | | | | / /\ \ | | | | \ \______| |
|
||||
* | | | | /_/ \_\ | | | | \_________|
|
||||
*
|
||||
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
|
||||
*/
|
||||
|
||||
#define JPUSH_VERSION_NUMBER 2.1.0
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class CLRegion;
|
||||
@class UILocalNotification;
|
||||
|
||||
extern NSString *const kJPFNetworkIsConnectingNotification; // 正在连接中
|
||||
extern NSString *const kJPFNetworkDidSetupNotification; // 建立连接
|
||||
extern NSString *const kJPFNetworkDidCloseNotification; // 关闭连接
|
||||
extern NSString *const kJPFNetworkDidRegisterNotification; // 注册成功
|
||||
extern NSString *const kJPFNetworkDidLoginNotification; // 登录成功
|
||||
extern NSString *const kJPFNetworkDidReceiveMessageNotification; // 收到消息(非APNS)
|
||||
extern NSString *const kJPFServiceErrorNotification; // 错误提示
|
||||
|
||||
@class CLLocation;
|
||||
|
||||
|
||||
/*!
|
||||
* JPush 核心头文件
|
||||
*/
|
||||
@interface JPUSHService : NSObject
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Setup 启动相关
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract 启动SDK
|
||||
*
|
||||
* @discussion 这是旧版本的启动方法, 依赖于 PushConfig.plist 文件. 建议不要使用, 已经过期.
|
||||
*/
|
||||
+ (void)setupWithOption:(NSDictionary *)launchingOption __attribute__((deprecated("JPush 2.1.0 版本已过期")));
|
||||
|
||||
/*!
|
||||
* @abstract 启动SDK
|
||||
*
|
||||
* @param launchingOption 启动参数.
|
||||
* @param appKey 一个JPush 应用必须的,唯一的标识. 请参考 JPush 相关说明文档来获取这个标识.
|
||||
* @param channel 发布渠道. 可选.
|
||||
* @param isProduction 是否生产环境. 如果为开发状态,设置为 NO; 如果为生产状态,应改为 YES.
|
||||
*
|
||||
* @discussion 提供SDK启动必须的参数, 来启动 SDK.
|
||||
* 此接口必须在 App 启动时调用, 否则 JPush SDK 将无法正常工作.
|
||||
*/
|
||||
+ (void)setupWithOption:(NSDictionary *)launchingOption
|
||||
appKey:(NSString *)appKey
|
||||
channel:(NSString *)channel
|
||||
apsForProduction:(BOOL)isProduction;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name APNs about 通知相关
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract 注册要处理的远程通知类型
|
||||
*
|
||||
* @param types 通知类型
|
||||
* @param categories
|
||||
*
|
||||
* @discussion
|
||||
*/
|
||||
+ (void)registerForRemoteNotificationTypes:(NSUInteger)types
|
||||
categories:(NSSet *)categories;
|
||||
|
||||
+ (void)registerDeviceToken:(NSData *)deviceToken;
|
||||
|
||||
/*!
|
||||
* @abstract 处理收到的 APNs 消息
|
||||
*/
|
||||
+ (void)handleRemoteNotification:(NSDictionary *)remoteInfo;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Tag alias setting 设置别名与标签
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* 下面的接口是可选的
|
||||
* 设置标签和(或)别名(若参数为nil,则忽略;若是空对象,则清空;详情请参考文档:http://docs.jpush.io/client/ios_api/#api-ios)
|
||||
* setTags:alias:fetchCompletionHandle:是新的设置标签别名的方法,不再需要显示声明回调函数,只需要在block里面处理设置结果即可.
|
||||
* WARN: 使用block时需要注意循环引用问题
|
||||
*/
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
target:(id)theTarget;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
alias:(NSString *)alias
|
||||
fetchCompletionHandle:(void (^)(int iResCode, NSSet *iTags, NSString *iAlias))completionHandler;
|
||||
|
||||
+ (void) setTags:(NSSet *)tags
|
||||
aliasInbackground:(NSString *)alias;
|
||||
|
||||
+ (void)setAlias:(NSString *)alias
|
||||
callbackSelector:(SEL)cbSelector
|
||||
object:(id)theTarget;
|
||||
|
||||
/*!
|
||||
* @abstract 过滤掉无效的 tags
|
||||
*
|
||||
* @discussion 如果 tags 数量超过限制数量, 则返回靠前的有效的 tags.
|
||||
* 建议设置 tags 前用此接口校验. SDK 内部也会基于此接口来做过滤.
|
||||
*/
|
||||
+ (NSSet *)filterValidTags:(NSSet *)tags;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Stats 统计功能
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract 开始记录页面停留
|
||||
*
|
||||
* @param pageName 页面名称
|
||||
*/
|
||||
+ (void)startLogPageView:(NSString *)pageName;
|
||||
|
||||
/*!
|
||||
* @abstract 停止记录页面停留
|
||||
*
|
||||
* @param pageName 页面
|
||||
*/
|
||||
+ (void)stopLogPageView:(NSString *)pageName;
|
||||
|
||||
/*!
|
||||
* @abstract 直接上报在页面的停留时工
|
||||
*
|
||||
* @param pageName 页面
|
||||
* @param seconds 停留的秒数
|
||||
*/
|
||||
+ (void)beginLogPageView:(NSString *)pageName duration:(int)seconds;
|
||||
|
||||
/*!
|
||||
* @abstract 开启Crash日志收集
|
||||
*
|
||||
* @discussion 默认是关闭状态.
|
||||
*/
|
||||
+ (void)crashLogON;
|
||||
|
||||
/*!
|
||||
* @abstract 地理位置上报
|
||||
*
|
||||
* @param latitude 纬度.
|
||||
* @param longitude 经度.
|
||||
*
|
||||
*/
|
||||
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
|
||||
|
||||
/*!
|
||||
* @abstract 地理位置上报
|
||||
*
|
||||
* @param location 直接传递 CLLocation * 型的地理信息
|
||||
*
|
||||
* @discussion 需要链接 CoreLocation.framework 并且 #import <CoreLocation/CoreLocation.h>
|
||||
*/
|
||||
+ (void)setLocation:(CLLocation *)location;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Local Notification 本地通知
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract 本地推送,最多支持64个
|
||||
*
|
||||
* @param fireDate 本地推送触发的时间
|
||||
* @param alertBody 本地推送需要显示的内容
|
||||
* @param badge 角标的数字。如果不需要改变角标传-1
|
||||
* @param alertAction 弹框的按钮显示的内容(IOS 8默认为"打开", 其他默认为"启动")
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @param userInfo 自定义参数,可以用来标识推送和增加附加信息
|
||||
* @param soundName 自定义通知声音,设置为nil为默认声音
|
||||
*
|
||||
* @discussion 最多支持 64 个定义
|
||||
*/
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
badge:(int)badge
|
||||
alertAction:(NSString *)alertAction
|
||||
identifierKey:(NSString *)notificationKey
|
||||
userInfo:(NSDictionary *)userInfo
|
||||
soundName:(NSString *)soundName;
|
||||
|
||||
/*!
|
||||
* @abstract 本地推送 (支持 iOS8 新参数)
|
||||
*
|
||||
* IOS8新参数
|
||||
* @param region 自定义参数
|
||||
* @param regionTriggersOnce 自定义参数
|
||||
* @param category 自定义参数
|
||||
*/
|
||||
+ (UILocalNotification *)setLocalNotification:(NSDate *)fireDate
|
||||
alertBody:(NSString *)alertBody
|
||||
badge:(int)badge
|
||||
alertAction:(NSString *)alertAction
|
||||
identifierKey:(NSString *)notificationKey
|
||||
userInfo:(NSDictionary *)userInfo
|
||||
soundName:(NSString *)soundName
|
||||
region:(CLRegion *)region
|
||||
regionTriggersOnce:(BOOL)regionTriggersOnce
|
||||
category:(NSString *)category NS_AVAILABLE_IOS(8_0);
|
||||
|
||||
/*!
|
||||
* @abstract 前台展示本地推送
|
||||
*
|
||||
* @param notification 本地推送对象
|
||||
* @param notificationKey 需要前台显示的本地推送通知的标示符
|
||||
*
|
||||
* @discussion 默认App在前台运行时不会进行弹窗,在程序接收通知调用此接口可实现指定的推送弹窗。
|
||||
*/
|
||||
+ (void)showLocalNotificationAtFront:(UILocalNotification *)notification
|
||||
identifierKey:(NSString *)notificationKey;
|
||||
/*!
|
||||
* @abstract 删除本地推送定义
|
||||
*
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @param myUILocalNotification 本地推送对象
|
||||
*/
|
||||
+ (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
|
||||
|
||||
/*!
|
||||
* @abstract 删除本地推送定义
|
||||
*/
|
||||
+ (void)deleteLocalNotification:(UILocalNotification *)localNotification;
|
||||
|
||||
/*!
|
||||
* @abstract 获取指定通知
|
||||
*
|
||||
* @param notificationKey 本地推送标示符
|
||||
* @return 本地推送对象数组, [array count]为0时表示没找到
|
||||
*/
|
||||
+ (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
|
||||
|
||||
/*!
|
||||
* @abstract 清除所有本地推送对象
|
||||
*/
|
||||
+ (void)clearAllLocalNotifications;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Server badge 服务器端 badge 功能
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract 设置角标(到服务器)
|
||||
*
|
||||
* @param value 新的值. 会覆盖服务器上保存的值(这个用户)
|
||||
*
|
||||
* @discussion 本接口不会改变应用本地的角标值.
|
||||
* 本地仍须调用 UIApplication:setApplicationIconBadgeNumber 函数来设置脚标.
|
||||
*
|
||||
* 本接口用于配合 JPush 提供的服务器端角标功能.
|
||||
* 该功能解决的问题是, 服务器端推送 APNs 时, 并不知道客户端原来已经存在的角标是多少, 指定一个固定的数字不太合理.
|
||||
*
|
||||
* JPush 服务器端脚标功能提供:
|
||||
*
|
||||
* - 通过本 API 把当前客户端(当前这个用户的) 的实际 badge 设置到服务器端保存起来;
|
||||
* - 调用服务器端 API 发 APNs 时(通常这个调用是批量针对大量用户),
|
||||
* 使用 "+1" 的语义, 来表达需要基于目标用户实际的 badge 值(保存的) +1 来下发通知时带上新的 badge 值;
|
||||
*/
|
||||
+ (BOOL)setBadge:(NSInteger)value;
|
||||
|
||||
/*!
|
||||
* @abstract 重置脚标(为0)
|
||||
*
|
||||
* @discussion 相当于 [setBadge:0] 的效果.
|
||||
* 参考 [JPUSHService setBadge:] 说明来理解其作用.
|
||||
*/
|
||||
+ (void)resetBadge;
|
||||
|
||||
|
||||
///----------------------------------------------------
|
||||
/// @name Logs and others 日志与其他
|
||||
///----------------------------------------------------
|
||||
|
||||
/*!
|
||||
* @abstract JPush标识此设备的 registrationID
|
||||
*
|
||||
* @discussion SDK注册成功后, 调用此接口获取到 registrationID 才能够获取到.
|
||||
*
|
||||
* JPush 支持根据 registrationID 来进行推送.
|
||||
* 如果你需要此功能, 应该通过此接口获取到 registrationID 后, 上报到你自己的服务器端, 并保存下来.
|
||||
*
|
||||
* 更多的理解请参考 JPush 的文档网站.
|
||||
*/
|
||||
+ (NSString *)registrationID;
|
||||
|
||||
/*!
|
||||
* @abstract 打开日志级别到 Debug
|
||||
*
|
||||
* @discussion JMessage iOS 的日志系统参考 Android 设计了级别.
|
||||
* 从低到高是: Verbose, Debug, Info, Warning, Error.
|
||||
* 对日志级别的进一步理解, 请参考 Android 相关的说明.
|
||||
*
|
||||
* SDK 默认开启的日志级别为: Info. 只显示必要的信息, 不打印调试日志.
|
||||
*
|
||||
* 调用本接口可打开日志级别为: Debug, 打印调试日志.
|
||||
*/
|
||||
+ (void)setDebugMode;
|
||||
|
||||
/*!
|
||||
* @abstract 关闭日志
|
||||
*
|
||||
* @discussion 关于日志级别的说明, 参考 [JPUSHService setDebugMode]
|
||||
*
|
||||
* 虽说是关闭日志, 但还是会打印 Warning, Error 日志. 这二种日志级别, 在程序运行正常时, 不应有打印输出.
|
||||
*
|
||||
* 建议在发布的版本里, 调用此接口, 关闭掉日志打印.
|
||||
*/
|
||||
+ (void)setLogOFF;
|
||||
|
||||
|
||||
@end
|
||||
BIN
src/ios/lib/jpush-ios-2.1.0.a
Normal file
BIN
src/ios/lib/jpush-ios-2.1.0.a
Normal file
Binary file not shown.
Binary file not shown.
@@ -1,323 +1,345 @@
|
||||
|
||||
|
||||
var JPushPlugin = function(){
|
||||
};
|
||||
|
||||
//private plugin function
|
||||
|
||||
JPushPlugin.prototype.receiveMessage={}
|
||||
JPushPlugin.prototype.openNotification={}
|
||||
JPushPlugin.prototype.receiveNotification={}
|
||||
JPushPlugin.prototype.receiveMessage = {}
|
||||
JPushPlugin.prototype.openNotification = {}
|
||||
JPushPlugin.prototype.receiveNotification = {}
|
||||
|
||||
|
||||
JPushPlugin.prototype.isPlatformIOS = function(){
|
||||
return device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch" || device.platform == "iOS"
|
||||
JPushPlugin.prototype.isPlatformIOS = function() {
|
||||
var isPlatformIOS = device.platform == "iPhone"
|
||||
|| device.platform == "iPad"
|
||||
|| device.platform == "iPod touch"
|
||||
|| device.platform == "iOS";
|
||||
return isPlatformIOS;
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.error_callback = function(msg){
|
||||
console.log("Javascript Callback Error: " + msg)
|
||||
JPushPlugin.prototype.error_callback = function(msg) {
|
||||
console.log("Javascript Callback Error: " + msg);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.call_native = function(name, args, callback){
|
||||
|
||||
ret = cordova.exec(callback,this.error_callback,'JPushPlugin',name,args);
|
||||
JPushPlugin.prototype.call_native = function(name, args, callback) {
|
||||
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//public plugin function
|
||||
|
||||
JPushPlugin.prototype.startLogPageView = function(pageName){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "startLogPageView",[pageName],null);
|
||||
}
|
||||
JPushPlugin.prototype.startLogPageView = function(pageName) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("startLogPageView", [pageName], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopLogPageView = function(pageName){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "stopLogPageView",[pageName],null);
|
||||
JPushPlugin.prototype.stopLogPageView = function(pageName) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("stopLogPageView", [pageName], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "beginLogPageView",[pageName,duration],null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "setApplicationIconBadgeNumber",[badge],null);
|
||||
JPushPlugin.prototype.beginLogPageView = function(pageName, duration) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("beginLogPageView", [pageName, duration], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags,alias){
|
||||
try{
|
||||
if(tags==null){
|
||||
this.setAlias(alias);
|
||||
return;
|
||||
}
|
||||
if(alias==null){
|
||||
this.setTags(tags);
|
||||
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("setApplicationIconBadgeNumber", [badge], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
|
||||
if(this.isPlatformIOS()) {
|
||||
this.call_native("getApplicationIconBadgeNumber", [], callback);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias) {
|
||||
try {
|
||||
if(tags == null) {
|
||||
this.setAlias(alias);
|
||||
return;
|
||||
}
|
||||
if(alias == null) {
|
||||
this.setTags(tags);
|
||||
return;
|
||||
}
|
||||
var arrayTagWithAlias=[tags];
|
||||
var arrayTagWithAlias = [tags];
|
||||
arrayTagWithAlias.unshift(alias);
|
||||
this.call_native( "setTagsWithAlias", arrayTagWithAlias,null);
|
||||
}
|
||||
catch(exception){
|
||||
this.call_native("setTagsWithAlias", arrayTagWithAlias, null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.setTags = function(tags){
|
||||
|
||||
try{
|
||||
this.call_native("setTags",tags,null);
|
||||
}
|
||||
catch(exception){
|
||||
|
||||
JPushPlugin.prototype.setTags = function(tags) {
|
||||
try {
|
||||
this.call_native("setTags", tags, null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setAlias = function(alias){
|
||||
try{
|
||||
this.call_native("setAlias",[alias],null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback){
|
||||
|
||||
try{
|
||||
var data=[];
|
||||
this.call_native("getRegistrationID",[data],callback);
|
||||
}
|
||||
catch(exception){
|
||||
JPushPlugin.prototype.setAlias = function(alias) {
|
||||
try {
|
||||
this.call_native("setAlias", [alias], null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setBadge = function(value){
|
||||
|
||||
if(this.isPlatformIOS()){
|
||||
try{
|
||||
this.call_native("setBadge",[value],null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
}
|
||||
JPushPlugin.prototype.getRegistrationID = function(callback) {
|
||||
try {
|
||||
var data = [];
|
||||
this.call_native("getRegistrationID", [data], callback);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.resetBadge = function(){
|
||||
|
||||
if(this.isPlatformIOS()){
|
||||
try{
|
||||
var data=[];
|
||||
this.call_native("resetBadge",[data],null);
|
||||
}
|
||||
catch(exception){
|
||||
console.log(exception);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setBadge = function(value) {
|
||||
if(this.isPlatformIOS()) {
|
||||
try {
|
||||
this.call_native("setBadge", [value], null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resetBadge = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
try {
|
||||
var data = [];
|
||||
this.call_native("resetBadge", [data], null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugModeFromIos = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("setDebugModeFromIos", [data], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLogOFF = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("setLogOFF", [data], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCrashLogON = function() {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("crashLogON", [data], null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.setDebugModeFromIos = function(){
|
||||
if(this.isPlatformIOS()){
|
||||
var data=[];
|
||||
this.call_native("setDebugModeFromIos",[data],null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addLocalNotificationForIOS = function(delayTime, content,
|
||||
badge, notificationID, extras) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [delayTime, content, badge, notificationID, extras];
|
||||
this.call_native("setLocalNotification", data, null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.setLogOFF = function(){
|
||||
if(this.isPlatformIOS()){
|
||||
var data=[];
|
||||
this.call_native("setLogOFF",[data],null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function(
|
||||
identifierKey) {
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [identifierKey];
|
||||
this.call_native("deleteLocalNotificationWithIdentifierKey", data, null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data){
|
||||
try{
|
||||
console.log("JPushPlugin:receiveMessageIniOSCallback--data:"+data);
|
||||
|
||||
JPushPlugin.prototype.clearAllLocalNotifications = function(){
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("clearAllLocalNotifications", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLocation = function(latitude, longitude){
|
||||
if (this.isPlatformIOS()) {
|
||||
var data = [latitude, longitude];
|
||||
this.call_native("setLocation", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:receiveMessageIniOSCallback--data:" + data);
|
||||
var bToObj = JSON.parse(data);
|
||||
var content = bToObj.content;
|
||||
console.log(content);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:receiveMessageIniOSCallback"+exception);
|
||||
console.log(content);
|
||||
} catch(exception) {
|
||||
console.log("JPushPlugin:receiveMessageIniOSCallback" + exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data){
|
||||
try{
|
||||
|
||||
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:receiveMessageInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveMessage=bToObj
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage',null);
|
||||
//console.log(data);
|
||||
//var message = bToObj.message;
|
||||
//var extras = bToObj.extras;
|
||||
|
||||
//console.log(message);
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['cn.jpush.android.CONTENT_TYPE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
}
|
||||
catch(exception){
|
||||
console.log("JPushPlugin:pushCallback "+exception);
|
||||
data = JSON.stringify(data);
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveMessage = bToObj
|
||||
cordova.fireDocumentEvent('jpush.receiveMessage', null);
|
||||
} catch(exception) {
|
||||
console.log("JPushPlugin:pushCallback " + exception);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data){
|
||||
try{
|
||||
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data) {
|
||||
try {
|
||||
console.log("JPushPlugin:openNotificationInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.openNotification=bToObj;
|
||||
cordova.fireDocumentEvent('jpush.openNotification',null);
|
||||
|
||||
//console.log(data);
|
||||
//var bToObj = JSON.parse(data);
|
||||
//var alert = bToObj.alert;
|
||||
//var extras = bToObj.extras;
|
||||
//console.log(alert);
|
||||
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['app']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
//console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||
//console.log("JPushPlugin:openNotificationCallback is ready");
|
||||
}
|
||||
catch(exception){
|
||||
data = JSON.stringify(data);
|
||||
var bToObj = JSON.parse(data);
|
||||
this.openNotification = bToObj;
|
||||
cordova.fireDocumentEvent('jpush.openNotification', null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data){
|
||||
|
||||
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data) {
|
||||
try{
|
||||
console.log("JPushPlugin:receiveNotificationInAndroidCallback");
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveNotification=bToObj;
|
||||
cordova.fireDocumentEvent('jpush.receiveNotification',null);
|
||||
|
||||
//console.log(data);
|
||||
//var bToObj = JSON.parse(data);
|
||||
//var alert = bToObj.alert;
|
||||
//var extras = bToObj.extras;
|
||||
//console.log(alert);
|
||||
|
||||
//console.log(extras['cn.jpush.android.MSG_ID']);
|
||||
//console.log(extras['app']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_CONTENT_TITLE']);
|
||||
//console.log(extras['cn.jpush.android.EXTRA']);
|
||||
//console.log(extras['cn.jpush.android.PUSH_ID']);
|
||||
//console.log(extras['cn.jpush.android.NOTIFICATION_ID']);
|
||||
//console.log("JPushPlugin:openNotificationCallback is ready");
|
||||
}
|
||||
catch(exception){
|
||||
data = JSON.stringify(data);
|
||||
var bToObj = JSON.parse(data);
|
||||
this.receiveNotification = bToObj;
|
||||
cordova.fireDocumentEvent('jpush.receiveNotification', null);
|
||||
} catch(exception) {
|
||||
console.log(exception);
|
||||
}
|
||||
}
|
||||
|
||||
//android single
|
||||
|
||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function(){
|
||||
JPushPlugin.prototype.setBasicPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data=[]
|
||||
this.call_native("setBasicPushNotificationBuilder",data,null);
|
||||
data = [];
|
||||
this.call_native("setBasicPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setCustomPushNotificationBuilder = function(){
|
||||
JPushPlugin.prototype.setCustomPushNotificationBuilder = function() {
|
||||
if(device.platform == "Android") {
|
||||
data=[];
|
||||
this.call_native("setCustomPushNotificationBuilder",data,null);
|
||||
data = [];
|
||||
this.call_native("setCustomPushNotificationBuilder", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.stopPush = function(){
|
||||
data=[];
|
||||
this.call_native("stopPush",data,null);
|
||||
JPushPlugin.prototype.stopPush = function() {
|
||||
data = [];
|
||||
this.call_native("stopPush", data, null);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.resumePush = function(){
|
||||
data=[]
|
||||
this.call_native("resumePush",data,null);
|
||||
|
||||
JPushPlugin.prototype.resumePush = function() {
|
||||
data = [];
|
||||
this.call_native("resumePush", data, null);
|
||||
}
|
||||
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode",[mode],null);
|
||||
this.call_native("setDebugMode", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
//setDebugMode
|
||||
JPushPlugin.prototype.clearAllNotification = function(){
|
||||
JPushPlugin.prototype.clearAllNotification = function() {
|
||||
if(device.platform == "Android") {
|
||||
data=[]
|
||||
this.call_native("clearAllNotification",data,null);
|
||||
data = [];
|
||||
this.call_native("clearAllNotification", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLatestNotificationNum = function(num){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setLatestNotificationNum",[num],null);
|
||||
JPushPlugin.prototype.clearNotificationById = function(notificationId) {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("clearNotificationById", [notificationId], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.isPushStopped = function(callback){
|
||||
|
||||
data=[];
|
||||
this.call_native("isPushStopped",data,callback)
|
||||
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.init = function(){
|
||||
if(this.isPlatformIOS()){
|
||||
var data=[];
|
||||
this.call_native("initial",data,null);
|
||||
}else{
|
||||
data=[];
|
||||
this.call_native("init",data,null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode){
|
||||
JPushPlugin.prototype.setLatestNotificationNum = function(num) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setDebugMode",[mode],null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.addLocalNotification = function(builderId,content,title,notificaitonID,broadcastTime,extras){
|
||||
if(device.platform == "Android") {
|
||||
data=[builderId,content,title,notificaitonID,broadcastTime,extras];
|
||||
this.call_native("addLocalNotification",data,null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.removeLocalNotification = function(notificationID){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("removeLocalNotification",[notificationID],null);
|
||||
}
|
||||
}
|
||||
JPushPlugin.prototype.clearLocalNotifications = function(){
|
||||
if(device.platform == "Android") {
|
||||
data=[]
|
||||
this.call_native("clearLocalNotifications",data,null);
|
||||
this.call_native("setLatestNotificationNum", [num], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.reportNotificationOpened = function(msgID){
|
||||
JPushPlugin.prototype.isPushStopped = function(callback) {
|
||||
data = [];
|
||||
this.call_native("isPushStopped", data, callback);
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.init = function() {
|
||||
if(this.isPlatformIOS()) {
|
||||
var data = [];
|
||||
this.call_native("initial", data, null);
|
||||
} else {
|
||||
data = [];
|
||||
this.call_native("init", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setDebugMode = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
|
||||
this.call_native("reportNotificationOpened",[msgID],null);
|
||||
this.call_native("setDebugMode", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
|
||||
notificaitonID, broadcastTime, extras) {
|
||||
if(device.platform == "Android") {
|
||||
data = [builderId, content, title, notificaitonID, broadcastTime, extras];
|
||||
this.call_native("addLocalNotification", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.removeLocalNotification = function(notificationID) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("removeLocalNotification", [notificationID], null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearLocalNotifications = function() {
|
||||
if(device.platform == "Android") {
|
||||
data = [];
|
||||
this.call_native("clearLocalNotifications", data, null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.reportNotificationOpened = function(msgID) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("reportNotificationOpened", [msgID], null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*是否开启统计分析功能,用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器上,
|
||||
*在 Portal 上展示给开发者。
|
||||
**/
|
||||
JPushPlugin.prototype.setStatisticsOpen = function(mode) {
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setStatisticsOpen", [mode], null);
|
||||
}
|
||||
}
|
||||
|
||||
//iOS single
|
||||
|
||||
|
||||
if(!window.plugins){
|
||||
if(!window.plugins) {
|
||||
window.plugins = {};
|
||||
}
|
||||
|
||||
if(!window.plugins.jPushPlugin){
|
||||
if(!window.plugins.jPushPlugin) {
|
||||
window.plugins.jPushPlugin = new JPushPlugin();
|
||||
}
|
||||
|
||||
module.exports = new JPushPlugin();
|
||||
}
|
||||
|
||||
module.exports = new JPushPlugin();
|
||||
|
||||
Reference in New Issue
Block a user