diff --git a/README.md b/README.md
index 66844c1..ab2c7b0 100644
--- a/README.md
+++ b/README.md
@@ -30,9 +30,9 @@
## Usage
### API
-- [公共 API](/doc/Common_detail_api.md)
-- [iOS API](/doc/iOS_API.md)
-- [Android API](/doc/Android_detail_api.md)
+- [Common](/doc/Common_detail_api.md)
+- [iOS](/doc/iOS_API.md)
+- [Android](/doc/Android_detail_api.md)
### Demo
插件项目中包含一个简单的 Demo。若想参考,可以在 */example* 文件夹内找到并拷贝以下文件:
@@ -53,8 +53,8 @@
### iOS
#### PushConfig.plist 文件中的字段都是什么意思?
-- APP_KEY:应用标识。
-- CHANNEL:渠道标识。
+- Appkey:应用标识。
+- Channel:渠道标识。
- IsProduction:是否生产环境。
- IsIDFA:是否使用 IDFA 启动 SDK。
diff --git a/doc/Android_detail_api.md b/doc/Android_detail_api.md
index c1c06ea..6bf5a5d 100644
--- a/doc/Android_detail_api.md
+++ b/doc/Android_detail_api.md
@@ -157,6 +157,19 @@
window.plugins.jPushPlugin.clearAllNotification()
+### API - clearNotificationById
+根据通知 Id 清除通知(包括本地通知)。
+
+#### 接口定义
+
+ window.plugins.jPushPlugin.clearNotificationById(notificationId)
+
+#### 参数说明
+- notificationId:int,通知的 id。
+
+#### 代码示例
+
+ window.plugins.jPushPlugin.clearNotificationById(1)
## 设置允许推送时间
diff --git a/doc/Common_detail_api.md b/doc/Common_detail_api.md
index 0474009..115c607 100644
--- a/doc/Common_detail_api.md
+++ b/doc/Common_detail_api.md
@@ -17,11 +17,9 @@
本功能是一个完全本地的状态操作,也就是说:停止推送服务的状态不会保存到服务器上。
-如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,
-JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数据被清除掉了)。
+如果停止推送服务后,开发者 App 被重新安装,或者被清除数据,JPush SDK 会恢复正常的默认行为(因为保存在本地的状态数据被清除掉了)。
-本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,
-恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
+本功能其行为类似于网络中断的效果,即:推送服务停止期间推送的消息,恢复推送服务后,如果推送的消息还在保留的时长范围内,则客户端是会收到离线消息。
#### 接口定义
@@ -41,8 +39,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
+ iOS 平台:
- + 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
- + 推荐:设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务。
+ + 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。**建议设置一个 UI 界面, 提醒用户在 设置-通知 中关闭推送服务**。
#### 接口定义
@@ -59,7 +56,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
+ iOS 平台:
- + 重新去APNS注册。
+ + 重新去 APNS 注册。
#### 接口定义
@@ -78,7 +75,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
#### 接口定义
- window.plugins.jPushPlugin.isPushStopped(callback)
+ window.plugins.jPushPlugin.isPushStopped(callback)
#### 参数说明
@@ -116,14 +113,9 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 代码示例
- window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
- var onGetRegistradionID = function(data) {
- try {
- console.log("JPushPlugin:registrationID is " + data);
- } catch(exception) {
- console.log(exception);
- }
- }
+ window.plugins.jPushPlugin.getRegistrationID(function(data) {
+ console.log("JPushPlugin:registrationID is " + data)
+ })
## 设置别名与标签
@@ -143,7 +135,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
系统不限定一个别名只能指定一个用户。如果一个别名被指定到了多个用户,当给指定这个别名发消息时,服务器端 API 会同时给这多个用户发送消息。
-举例:在一个用户要登录的游戏中,可能设置别名为 userid。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userid 调用服务器端 API 发通知到客户端提醒用户。
+举例:在一个用户要登录的游戏中,可能设置别名为 userId。游戏运营时,发现该用户 3 天没有玩游戏了,则根据 userId 调用服务器端 API 发通知到客户端提醒用户。
**标签 Tag**:
@@ -181,18 +173,13 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果:
- document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
- 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);
- }
- }
+ document.addEventListener("jpush.setTagsWithAlias", function(event) {
+ console.log("onTagsWithAlias")
+ var result = "result code:" + event.resultCode + " "
+ result += "tags:" + event.tags + " "
+ result += "alias:" + event.alias + " "
+ $("#tagAliasResult").html(result)
+ }, false)
#### 错误码定义
@@ -219,19 +206,16 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.openNotification", onOpenNotification, false);
+ document.addEventListener("jpush.openNotification", function (event) {
+ var alertContent
+ if(device.platform == "Android") {
+ alertContent = event.alert
+ } else {
+ lertContent = event.aps.alert
+ }
+ }, false)
-- onOpenNotification 需要这样写:
-
- var alertContent;
- if(device.platform == "Android") {
- alertContent = event.alert;
- } else {
- alertContent = event.aps.alert;
- }
- alert("open Notificaiton:" + alertContent);
-
-ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.openNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+ Android:
@@ -273,19 +257,18 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.o
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
+ document.addEventListener("jpush.receiveNotification", function (event) {
+ var alertContent
+ if(device.platform == "Android") {
+ alertContent = event.alert
+ } else {
+ alertContent = event.aps.alert
+ }
+ alert("open Notificaiton:" + alertContent)
+ }, false)
+
-- onReceiveNotification 需要这样写:
-
- var alertContent;
- if(device.platform == "Android") {
- alertContent = event.alert;
- } else {
- alertContent = event.aps.alert;
- }
- alert("open Notificaiton:" + alertContent);
-
-ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveNotification,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+ Android:
@@ -330,26 +313,16 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
+ document.addEventListener("jpush.receiveMessage", function (event) {
+ var message
+ if(device.platform == "Android") {
+ message = event.message;
+ } else {
+ message = event.content;
+ }
+ }, false)
-- onReceiveMessage 需要这样写:
-
- var onReceiveMessage = function(event) {
- try{
- var message
- if(device.platform == "Android") {
- message = event.message;
- } else {
- message = event.content;
- }
- $("#messageResult").html(message);
- } catch(exception) {
- console.log("JPushPlugin:onReceiveMessage-->" + exception);
- }
- }
-
-ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,
-直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+> ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.receiveMessage,直接访问即可,字段示例,根据实际推送情况,可能略有差别,请注意。
+ Android:
@@ -370,7 +343,6 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
"extras":{"key":"不填写没有"}
}
-
## 判断系统设置中是否允许当前应用推送
### API - getUserNotificationSettings
判断系统设置中是否允许当前应用推送。
@@ -392,5 +364,4 @@ ps:点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
// 系统设置中已关闭应用推送。
} else if(result > 0) {
// 系统设置中打开了应用推送。
- }
- });
+ })
diff --git a/doc/iOS_API.md b/doc/iOS_API.md
index 4c3b2c4..3ef7e10 100644
--- a/doc/iOS_API.md
+++ b/doc/iOS_API.md
@@ -21,7 +21,7 @@
### API - init
-调用此 API,用来开启 JPush SDK 提供的推送服务。
+调用此 API,用来开启 JPush SDK 提供的推送服务。
开发者 App 可以通过调用停止推送服务 API 来停止极光推送服务,当又需要使用极光推送服务时,则必须要调用恢复推送服务 API。
@@ -37,7 +37,6 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
window.plugins.jPushPlugin.init()
-
### API - stopPush
- 不推荐调用,因为这个 API 只是让你的 DeviceToken 失效,在 设置-通知 中您的应用程序没有任何变化。
@@ -45,8 +44,7 @@ JPush SDK 会恢复正常的默认行为。(因为保存在本地的状态数
#### 接口定义
- window.plugins.jPushPlugin.stopPush()
-
+ window.plugins.jPushPlugin.stopPush()
### API - resumePush
@@ -65,21 +63,19 @@ iOS平台,检查推送服务是否停止。
window.plugins.jPushPlugin.isPushStopped(callback)
-
#### 参数说明
- callback 回调函数,用来通知 JPush 的推送服务是否开启。
#### 代码示例
- window.plugins.jPushPlugin.isPushStopped(callback)
- var callback = function(data) {
- if(data > 0) {
- // 已关闭
- } else {
- // 已开启
- }
- }
+ window.plugins.jPushPlugin.isPushStopped(function(data) {
+ if(data > 0) {
+ // 已关闭
+ } else {
+ // 已开启
+ }
+ })
## 获取 RegistrationID
@@ -102,14 +98,9 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### 调用示例
- window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
- var onGetRegistradionID = function(data) {
- try {
- console.log("JPushPlugin:registrationID is " + data);
- } catch(exception) {
- console.log(exception);
- }
- }
+ window.plugins.jPushPlugin.getRegistrationID(function(data) {
+ console.log("JPushPlugin:registrationID is " + data)
+ })
## 别名与标签
@@ -167,18 +158,14 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
函数本身无返回值,但需要注册 `jpush.setTagsWithAlias` 事件来监听设置结果。
- document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
- 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 onTagsWithAlias = function(event) {
+ console.log("onTagsWithAlias")
+ var result = "result code:"+event.resultCode + " "
+ result += "tags:" + event.tags + " "
+ result += "alias:" + event.alias + " "
+ $("#tagAliasResult").html(result)
+ }
+ document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false)
#### 错误码定义
@@ -207,14 +194,14 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.openNotification", onOpenNotification, false);
+ document.addEventListener("jpush.openNotification", onOpenNotification, false)
- onOpenNotification 需要这样写:
var onOpenNotification = function(event) {
- var alertContent;
- alertContent = event.aps.alert;
- alert("open Notificaiton:" + alertContent);
+ var alertContent
+ alertContent = event.aps.alert
+ alert("open Notificaiton:" + alertContent)
}
- event 举例:
@@ -240,14 +227,14 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
+ document.addEventListener("jpush.receiveNotification", onReceiveNotification, false)
- onReceiveNotification 需要这样写:
var onReceiveNotification = function(event) {
- var alertContent;
- alertContent = event.aps.alert;
- alert("open Notificaiton:" + alertContent);
+ var alertContent
+ alertContent = event.aps.alert
+ alert("open Notificaiton:" + alertContent)
}
- event 举例
@@ -267,20 +254,20 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
#### event - jpush.backgroundNotification
-应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification)
+应用程序处于后台时收到推送会触发该事件,可以在后台执行一段代码。具体配置参考 [iOS 7 Background Remote Notification](https://docs.jiguang.cn/jpush/client/iOS/ios_new_fetures/#ios-7-background-remote-notification)
#### 代码示例
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false);
+ document.addEventListener("jpush.backgroundNotification", onBackgroundNotification, false)
- onBackgroundNotification 需要这样写:
var onBackgroundNotification = function(event) {
- var alertContent;
- alertContent = event.aps.alert;
- alert("open Notificaiton:" + alertContent);
+ var alertContent
+ alertContent = event.aps.alert
+ alert("open Notificaiton:" + alertContent)
}
+ event 举例
@@ -296,49 +283,29 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
"_j_msgid":154604475
}
-#### API - receiveMessageIniOSCallback
-
-用于 iOS 收到应用内消息的回调函数(请注意和通知的区别),该函数不需要主动调用
-不推荐使用回调函数
-
-##### 接口定义
-
- JPushPlugin.prototype.receiveMessageIniOSCallback(data)
-
-##### 参数说明
-
-- data: 是一个 js 字符串使用如下代码解析,js 具体 key 根据应用内消息来确定:
-
- var bToObj = JSON.parse(data);
-
-
## 获取自定义消息内容
-
### event - jpush.receiveMessage
收到应用内消息时触发这个事件, 推荐使用事件的方式传递,但同时保留了 receiveMessageIniOSCallback 的回调函数,兼容以前的代码。
-
#### 代码示例
- 在你需要接收通知的的 js 文件中加入:
- document.addEventListener("jpush.receiveMessage", onReceiveMessage, false);
+ document.addEventListener("jpush.receiveMessage", onReceiveMessage, false)
- onReceiveMessage 需要这样写:
var onReceiveMessage = function(event) {
- try{
- var message;
- message = event.content;
- $("#messageResult").html(message);
- }catch(exception) {
+ try {
+ var message = event.content
+ $("#messageResult").html(message)
+ } catch(exception) {
console.log("JPushPlugin:onReceiveMessage-->" + exception);
}
}
-
- event 举例:
{
@@ -352,8 +319,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
## 设置Badge
### API - setBadge, resetBadge
- JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,
- 由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
+JPush 封装 badge 功能,允许应用上传 badge 值至 JPush 服务器,由 JPush 后台帮助管理每个用户所对应的推送 badge 值,简化了设置推送 badge 的操作。
(本接口不会直接改变应用本地的角标值. 要修改本地 badege 值,使用 setApplicationIconBadgeNumber)
实际应用中,开发者可以直接对 badge 值做增减操作,无需自己维护用户与 badge 值之间的对应关系。
@@ -362,7 +328,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
window.plugins.jPushPlugin.prototype.setBadge(value)
window.plugins.jPushPlugin.prototype.reSetBadge()
-resetBadge相当于setBadge(0)。
+resetBadge 相当于 setBadge(0)。
#### 参数说明
value 取值范围:[0,99999]。
@@ -372,8 +338,8 @@ value 取值范围:[0,99999]。
#### 代码示例
- window.plugins.jPushPlugin.setBadge(5);
- window.plugins.jPushPlugin.reSetBadge();
+ window.plugins.jPushPlugin.setBadge(5)
+ window.plugins.jPushPlugin.reSetBadge()
### API - setApplicationIconBadgeNumber
@@ -389,7 +355,7 @@ value 取值范围:[0,99999]。
#### 代码示例
- window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
+ window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0)
### API - getApplicationIconBadgeNumber
@@ -406,8 +372,8 @@ value 取值范围:[0,99999]。
#### 代码示例
window.plugins.jPushPlugin.getApplicationIconBadgeNumber(function(data) {
- console.log(data);
- });
+ console.log(data)
+ })
## 本地通知
@@ -446,7 +412,7 @@ value 取值范围:[0,99999]。
#### 代码示例
- window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier");
+ window.plugins.jPushPlugin.deleteLocalNotificationWithIdentifierKeyInIOS("identifier")
### API - clearAllLocalNotifications
@@ -458,7 +424,7 @@ value 取值范围:[0,99999]。
#### 代码示例
- window.plugins.jPushPlugin.clearAllLocalNotifications();
+ window.plugins.jPushPlugin.clearAllLocalNotifications()
## 页面的统计
@@ -630,7 +596,7 @@ iPhone 6s 及以后设备且 iOS 9 以后系统支持 3d-touch。
#### 接口定义
```
-window.plugins.jPushPlugin.prototype.addNotificationActions(actions, categoryId);
+window.plugins.jPushPlugin.prototype.addNotificationActions(actions, categoryId)
```
#### 参数说明
@@ -694,7 +660,7 @@ window.plugins.jPushPlugin.prototype.addNotificationActions(actions, categoryId)
#### 接口定义
```
-window.plugins.jPushPlugin.prototype.getUserNotificationSettings(callback);
+window.plugins.jPushPlugin.prototype.getUserNotificationSettings(callback)
```
#### 返回值
@@ -718,4 +684,3 @@ window.plugins.jPushPlugin.prototype.getUserNotificationSettings(callback);
- UNAlertStyleNone = 0
- UNAlertStyleBanner = 1
- UNAlertStyleAlert = 2
-
diff --git a/doc/iOS_install.md b/doc/iOS_install.md
index 6a58f5c..8d5582b 100644
--- a/doc/iOS_install.md
+++ b/doc/iOS_install.md
@@ -1,35 +1,39 @@
## iOS 手动安装
-- 下载 JPush PhoneGap Plugin 插件,并解压
+不建议使用手动安装,请参照 README.md 进行自动安装。
-- 将 [/src/ios](/src/ios) 文件夹及内容在 xcode 中拖到你的工程里,并配置 [/src/ios/PushConfig.plist](/src/ios/PushConfig.plist) 中相应参数:
+1. 下载 JPush PhoneGap Plugin 插件,并解压
+2. 将 [/src/ios](/src/ios) 文件夹及内容在 xcode 中拖到你的工程里,并配置 [/src/ios/PushConfig.plist](/src/ios/PushConfig.plist) 中相应参数:
- APP_KEY: 应用标识
- CHANNEL: 渠道标识
- IsProduction:是否生产环境
- IsIDFA: 是否使用 IDFA 启动 sdk
+ Appkey: 应用标识
+ Channel: 渠道标识
+ IsProduction:是否生产环境
+ IsIDFA: 是否使用 IDFA 启动 sdk
+3. 打开 xcode,点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
-- 打开 xcode,点击工程目录中顶部的 工程,选择(Target -> Build Phases -> Link Binary With Libraries),添加以下框架:
+ CFNetwork.framework
+ CoreFoundation.framework
+ CoreTelephony.framework
+ SystemConfiguration.framework
+ CoreGraphics.framework
+ Foundation.framework
+ UIKit.framework
+ AdSupport.framework
+ libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
+ UserNotifications.framework
+ libresolv.tbd
+4. 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
- CFNetwork.framework
- CoreFoundation.framework
- CoreTelephony.framework
- SystemConfiguration.framework
- CoreGraphics.framework
- Foundation.framework
- UIKit.framework
- AdSupport.framework
- libz.tbd(若存在 libz.dylib 则替换为 libz.tbd)
+```xml
+
+
+
+
+```
+5. 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
+6. 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
-- 修改 phonegap config.xml 文件以添加 JPushPlugin 插件
+```xml
+
+```
-
-
-
-
-
-- 将 [/www/JPushPlugin.js](/www/JPushPlugin.js) 在 xcode 中拖到工程的 www 目录下面
-
-- 在需要使用插件处加入以下代码,并根据 [iOS API](/doc/iOS_API.md) 文档说明调用相应接口
-
-
diff --git a/plugin.xml b/plugin.xml
index e6f8d8b..ba51f47 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -32,11 +32,11 @@
-
-
-
+
+
+
@@ -49,9 +49,10 @@
+
-
+
$API_KEY
diff --git a/src/ios/Plugins/AppDelegate+JPush.h b/src/ios/Plugins/AppDelegate+JPush.h
index 30219cc..5420b50 100644
--- a/src/ios/Plugins/AppDelegate+JPush.h
+++ b/src/ios/Plugins/AppDelegate+JPush.h
@@ -1,15 +1,15 @@
-//
-// AppDelegate+JPush.h
-// delegateExtention
-//
-// Created by 张庆贺 on 15/8/3.
-// Copyright (c) 2015年 JPush. All rights reserved.
-//
-
-#import "AppDelegate.h"
-#import
-#import "JPUSHService.h"
-
-@interface AppDelegate (JPush)
--(void)registerForIos10RemoteNotification;
-@end
+//
+// AppDelegate+JPush.h
+// delegateExtention
+//
+// Created by pikacode@qq.com on 15/8/3.
+// Copyright (c) 2015年 JPush. All rights reserved.
+//
+
+#import "AppDelegate.h"
+#import
+#import "JPUSHService.h"
+
+@interface AppDelegate (JPush)
+-(void)registerForRemoteNotification;
+@end
diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m
index 2a18ee0..f01a1fc 100644
--- a/src/ios/Plugins/AppDelegate+JPush.m
+++ b/src/ios/Plugins/AppDelegate+JPush.m
@@ -1,101 +1,132 @@
-//
-// 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
-#import
-#import
-
-
-
-@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) {
- [self registerForIos10RemoteNotification];
- [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];
-}
-
--(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
-
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
-
- [userInfo setValue:kJPushPluginiOS10ForegroundReceiveNotification forKey:@"JPushNotificationType"];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ForegroundReceiveNotification object:userInfo];
-
- completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
-}
-
--(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
- NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
- @try {
- [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
- } @catch (NSException *exception) { }
- [userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
- [userInfo setValue:kJPushPluginiOS10ClickNotification forKey:@"JPushNotificationType"];
- [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ClickNotification object:userInfo];
- completionHandler();
-}
-
--(void)registerForIos10RemoteNotification{
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
-#ifdef NSFoundationVersionNumber_iOS_9_x_Max
- JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
- entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
- [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
-#endif
- }
-}
-
-@end
+//
+// AppDelegate+JPush.m
+// delegateExtention
+//
+// Created by pikacode@qq.com on 15/8/3.
+// Copyright (c) 2015年 JPush. All rights reserved.
+//
+
+#import "AppDelegate+JPush.h"
+#import "JPushPlugin.h"
+#import
+#import
+#import
+#import "JPushDefine.h"
+
+@implementation AppDelegate (JPush)
+
++(void)load{
+ Method origin1;
+ Method swizzle1;
+ origin1 = class_getInstanceMethod([self class],@selector(init));
+ swizzle1 = class_getInstanceMethod([self class], @selector(init_plus));
+ method_exchangeImplementations(origin1, swizzle1);
+}
+
+-(instancetype)init_plus{
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidLaunch:) name:UIApplicationDidFinishLaunchingNotification object:nil];
+ return [self init_plus];
+}
+
+
+
+-(void)applicationDidLaunch:(NSNotification *)notification{
+ if (notification) {
+ if (notification.userInfo) {
+ NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
+ if (userInfo1.count > 0) {
+ [SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo1 toJsonString]];
+ }
+ NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
+ if (userInfo2.count > 0) {
+ [SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenLocalNotification jsString:[userInfo1 toJsonString]];
+ }
+ }
+ [JPUSHService setDebugMode];
+ [self registerForRemoteNotification];
+ [JPushPlugin setupJPushSDK:notification.userInfo];
+ }
+}
+
+-(void)registerForRemoteNotification{
+ if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
+#ifdef NSFoundationVersionNumber_iOS_9_x_Max
+ JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
+ entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
+ [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
+#endif
+ }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
+ //可以添加自定义categories
+ [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
+ UIUserNotificationTypeSound |
+ UIUserNotificationTypeAlert)
+ categories:nil];
+ } else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
+ //categories 必须为nil
+ [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
+ UIRemoteNotificationTypeSound |
+ UIRemoteNotificationTypeAlert)
+ categories:nil];
+ }
+}
+
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
+ [JPUSHService registerDeviceToken:deviceToken];
+}
+
+-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
+ [JPUSHService handleRemoteNotification:userInfo];
+
+ [SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
+}
+
+-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
+ [JPUSHService handleRemoteNotification:userInfo];
+ NSString *eventName;
+ switch ([UIApplication sharedApplication].applicationState) {
+ case UIApplicationStateInactive:
+ eventName = JPushDocumentEvent_OpenNotification;
+ break;
+ case UIApplicationStateActive:
+ eventName = JPushDocumentEvent_ReceiveNotification;
+ break;
+ case UIApplicationStateBackground:
+ eventName = JPushDocumentEvent_BackgoundNotification;
+ break;
+ default:
+ break;
+ }
+ [SharedJPushPlugin jpushFireDocumentEvent:eventName jsString:[userInfo toJsonString]];
+ completionHandler(UIBackgroundFetchResultNewData);
+}
+
+-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo];
+ [SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
+ completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
+}
+
+-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{
+ NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo];
+ @try {
+ [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"];
+ } @catch (NSException *exception) { }
+ [userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"];
+ [SharedJPushPlugin jpushFireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[userInfo toJsonString]];
+ completionHandler();
+}
+
+- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
+ // [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveLocalNotification object:notification.userInfo];
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ // [application setApplicationIconBadgeNumber:0];
+ // [application cancelAllLocalNotifications];
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ // [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
+}
+
+@end
diff --git a/src/ios/Plugins/JPushDefine.h b/src/ios/Plugins/JPushDefine.h
new file mode 100644
index 0000000..002721c
--- /dev/null
+++ b/src/ios/Plugins/JPushDefine.h
@@ -0,0 +1,31 @@
+//
+// ConstantDef.h
+// jmessage
+//
+// Created by pikacode@qq.com on 16/1/19.
+//
+//
+
+#ifndef ConstantDef_h
+#define ConstantDef_h
+
+
+
+#endif /* ConstantDef_h */
+
+#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
+
+static NSString *const JPushConfig_Appkey = @"Appkey";
+static NSString *const JPushConfig_Channel = @"Channel";
+static NSString *const JPushConfig_IsProduction = @"IsProduction";
+static NSString *const JPushConfig_IsIDFA = @"IsIDFA";
+static NSString *const JPushConfig_FileName = @"PushConfig";
+
+static NSString *const JPushDocumentEvent_ReceiveNotification = @"receiveNotification";
+static NSString *const JPushDocumentEvent_OpenNotification = @"openNotification";
+static NSString *const JPushDocumentEvent_BackgoundNotification = @"backgoundNotification";
+static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
+static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
+static NSString *const JPushDocumentEvent_OpenLocalNotification = @"openLocalNotification";
+
+
diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h
index abbb0e1..a0869f6 100644
--- a/src/ios/Plugins/JPushPlugin.h
+++ b/src/ios/Plugins/JPushPlugin.h
@@ -1,80 +1,91 @@
-//
-// PushTalkPlugin.h
-// PushTalk
-//
-// Created by zhangqinghe on 13-12-13.
-//
-//
-
-#import
-
-#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication"
-#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification"
-#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification"
-
-
-@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;
-
-//检查用户的推送设置情况
--(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
-
-//ios 10 APIs
--(void)addDismissActions:(CDVInvokedUrlCommand*)command;
--(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
-
-/*
- * 以下为js中可监听到的事件
- * jpush.openNotification 点击推送消息启动或唤醒app
- * jpush.setTagsWithAlias 设置标签、别名完成
- * jpush.receiveMessage 收到自定义消息
- * jpush.receiveNotification 前台收到推送
- * jpush.backgroundNotification 后台收到推送
- */
-
-@end
+//
+// PushTalkPlugin.h
+// PushTalk
+//
+// Created by pikacode@qq.com on 13-12-13.
+//
+//
+
+#import
+
+@interface JPushPlugin : CDVPlugin{
+
+}
+
+//以下为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;
+
+//检查用户的推送设置情况
+-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command;
+
+//ios 10 APIs
+-(void)addDismissActions:(CDVInvokedUrlCommand*)command;
+-(void)addNotificationActions:(CDVInvokedUrlCommand*)command;
+
+/*
+ * 以下为js中可监听到的事件
+ * jpush.openNotification 点击推送消息启动或唤醒app
+ * jpush.setTagsWithAlias 设置标签、别名完成
+ * jpush.receiveMessage 收到自定义消息
+ * jpush.receiveNotification 前台收到推送
+ * jpush.backgroundNotification 后台收到推送
+ */
+
+# pragma mark - private
+
+-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString;
+
++(void)setupJPushSDK:(NSDictionary*)userInfo;
+
+@end
+
+static JPushPlugin *SharedJPushPlugin;
+
+@interface NSDictionary (JPush)
+-(NSString*)toJsonString;
+@end
+
+@interface NSString (JPush)
+-(NSDictionary*)toDictionary;
+@end
+
+
diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m
index 64feb98..e659c66 100644
--- a/src/ios/Plugins/JPushPlugin.m
+++ b/src/ios/Plugins/JPushPlugin.m
@@ -1,484 +1,318 @@
-//
-// PushTalkPlugin.m
-// PushTalk
-//
-// Created by zhangqinghe on 13-12-13.
-//
-//
-
-#import "JPushPlugin.h"
-#import "JPUSHService.h"
-#import
-#import
-#import
-#import "AppDelegate+JPush.h"
-
-static NSString *const JP_APP_KEY = @"APP_KEY";
-static NSString *const JP_APP_CHANNEL = @"CHANNEL";
-static NSString *const JP_APP_ISPRODUCTION = @"IsProduction";
-static NSString *const JP_APP_ISIDFA = @"IsIDFA";
-static NSString *const JPushConfigFileName = @"PushConfig";
-static NSDictionary *_launchOptions = nil;
-
-#define WEAK_SELF(weakSelf) __weak __typeof(&*self)weakSelf = self;
-
-@implementation NSDictionary (JPush)
--(NSString*)toJsonString{
- NSError *error;
- NSData *data = [NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
- NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
- return jsonString;
-}
-@end
-
-@implementation NSString (JPush)
--(NSDictionary*)toDictionary{
- NSError *error;
- NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
- return dict;
-}
-@end
-
-@interface JPushPlugin()
-
-@end
-
-@implementation JPushPlugin
-
-#pragma mark- 外部接口
--(void)stopPush:(CDVInvokedUrlCommand*)command{
- [[UIApplication sharedApplication]unregisterForRemoteNotifications];
-}
-
--(void)resumePush:(CDVInvokedUrlCommand*)command{
- [JPushPlugin registerForRemoteNotification];
-}
-
--(void)isPushStopped:(CDVInvokedUrlCommand*)command{
- NSNumber *result;
- if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
- result = @(0);
- }else{
- result = @(1);
- }
- [self handleResultWithValue: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]) {
- [self initNotifications];
- }
- return self;
-}
-
-
-#endif
-
--(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];
-
- [defaultCenter addObserver:self
- selector:@selector(networkDidReceiveNotification:)
- name:kJPushPluginiOS10ForegroundReceiveNotification
- object:nil];
-
- [defaultCenter addObserver:self
- selector:@selector(networkDidReceiveNotification:)
- name:kJPushPluginiOS10ClickNotification
- object:nil];
-
-
- if (_launchOptions) {
- NSDictionary *userInfo = [_launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
- if ([userInfo count] >0) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",[userInfo toJsonString]]];
- });
- }
-
- }
-}
-
--(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{
-
- NSLog(@"#### setAlias %@",command.arguments);
- [JPUSHService setAlias:command.arguments[0]
- callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
- object:self];
-}
-
--(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
- NSString* registrationID = [JPUSHService registrationID];
- NSLog(@"### getRegistrationID %@",registrationID);
- [self handleResultWithValue: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)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 handleResultWithValue: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{
- NSString *identifier = [command argumentAtIndex:0];
- if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) {
- JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
- jpid.identifiers = @[identifier];
- [JPUSHService removeNotification:jpid];
- }else{
- [JPUSHService deleteLocalNotificationWithIdentifierKey:identifier];
- }
-}
-
--(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
- [JPUSHService clearAllLocalNotifications];
-}
-
--(void)setLocation:(CDVInvokedUrlCommand*)command{
- [JPUSHService setLatitude:[((NSString*)command.arguments[0]) doubleValue] longitude:[((NSString*)command.arguments[1]) doubleValue]];
-}
-
--(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
- WEAK_SELF(weakSelf);
- [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- dict[@"authorizationStatus"] = @(settings.authorizationStatus);
- dict[@"soundSetting"] = @(settings.soundSetting);
- dict[@"badgeSetting"] = @(settings.badgeSetting);
- dict[@"alertSetting"] = @(settings.alertSetting);
- dict[@"notificationCenterSetting"] = @(settings.notificationCenterSetting);
- dict[@"lockScreenSetting"] = @(settings.lockScreenSetting);
- dict[@"carPlaySetting"] = @(settings.carPlaySetting);
- dict[@"alertStyle"] = @(settings.alertStyle);
- [weakSelf handleResultWithValue:dict command:command];
- }];
- }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
- UIUserNotificationType type = settings.types;
- NSNumber *number = [NSNumber numberWithInteger:type];
- [self handleResultWithValue:number command:command];
- }else{
- UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
- NSNumber *number = [NSNumber numberWithInteger:type];
- [self handleResultWithValue:number command:command];
- }
-}
-
-#pragma mark - ios 10 APIs
-
--(void)addDismissActions:(CDVInvokedUrlCommand*)command{
- [self addActions:command dismiss:YES];
-}
-
--(void)addNotificationActions:(CDVInvokedUrlCommand*)command{
- [self addActions:command dismiss:NO];
-}
-
--(void)addActions:(CDVInvokedUrlCommand*)command dismiss:(BOOL)dimiss{
- NSArray *actionsData = [command argumentAtIndex:0];
- NSString *categoryId = [command argumentAtIndex:1];
- NSMutableArray *actions = [NSMutableArray array];
- for (NSDictionary *dict in actionsData) {
- NSString *title = dict[@"title"];
- NSString *identifier = dict[@"identifier"];
- NSString *option = dict[@"option"];
- NSString *type = dict[@"type"];
- if ([type isEqualToString:@"textInput"]) {
- NSString *textInputButtonTitle = dict[@"textInputButtonTitle"];
- NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
- UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
- [actions addObject:inputAction];
- }else{
- UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
- [actions addObject:action];
- }
- }
- UNNotificationCategory *category;
- if (dimiss) {
- category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
- }else{
- category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
- }
- [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
-}
-
-#pragma mark - 内部方法
-+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
- _launchOptions = 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:JP_APP_KEY];
- NSString * channel = [plistData valueForKey:JP_APP_CHANNEL];
- NSNumber * isProduction = [plistData valueForKey:JP_APP_ISPRODUCTION];
- NSNumber *isIDFA = [plistData valueForKey:JP_APP_ISIDFA];
-
- NSString *advertisingId = nil;
- if(isIDFA){
- advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
- }
- [JPUSHService setupWithOption:_launchOptions
- appKey:appkey
- channel:channel
- apsForProduction:[isProduction boolValue]
- advertisingIdentifier:advertisingId];
-
-}
-
-+(void)registerForRemoteNotification{
- [(AppDelegate*)[UIApplication sharedApplication].delegate registerForIos10RemoteNotification];
-
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- //可以添加自定义categories
- [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
- UIUserNotificationTypeSound |
- UIUserNotificationTypeAlert)
- categories:nil];
- } else if([[UIDevice currentDevice].systemVersion floatValue] < 8.0){
- //categories 必须为nil
- [JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
- UIRemoteNotificationTypeSound |
- UIRemoteNotificationTypeAlert)
- categories:nil];
- }
-}
-
-#pragma mark 将参数返回给js
--(void)handleResultWithValue:(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
- };
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.setTagsWithAlias',%@)",[dict toJsonString]]];
- });
-}
-
-- (void)networkDidReceiveMessage:(NSNotification *)notification {
- if (notification) {
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",[notification.userInfo toJsonString]]];
-
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"window.plugins.jPushPlugin.receiveMessageIniOSCallback('%@')",[notification.userInfo toJsonString]]];
-
- });
- }
-}
-
--(void)networkDidReceiveNotification:(NSNotification *)notification{
-
- NSError *error;
- NSDictionary *userInfo = [notification object];
-
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
- NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
-
- switch ([UIApplication sharedApplication].applicationState) {
- case UIApplicationStateActive:{
- //前台收到
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveNotification',%@)",jsonString]];
- });
- break;
- }
- case UIApplicationStateInactive:{
- //后台点击
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
- });
- break;
- }
- case UIApplicationStateBackground:{
- //后台收到
- dispatch_async(dispatch_get_main_queue(), ^{
- [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.backgoundNotification',%@)",jsonString]];
- });
- break;
- }
- default:
- //do nothing
- break;
- }
-
-}
-
-@end
+//
+// PushTalkPlugin.m
+// PushTalk
+//
+// Created by pikacode@qq.com on 13-12-13.
+//
+//
+
+#import "JPushPlugin.h"
+#import "JPUSHService.h"
+#import
+#import
+#import
+#import "AppDelegate+JPush.h"
+#import "JPushDefine.h"
+
+@implementation NSDictionary (JPush)
+-(NSString*)toJsonString{
+ NSError *error;
+ NSData *data = [NSJSONSerialization dataWithJSONObject:self options:0 error:&error];
+ NSString *jsonString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
+ return jsonString;
+}
+@end
+
+@implementation NSString (JPush)
+-(NSDictionary*)toDictionary{
+ NSError *error;
+ NSData *jsonData = [self dataUsingEncoding:NSUTF8StringEncoding];
+ NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
+ return dict;
+}
+@end
+
+@interface JPushPlugin()
+
+@end
+
+@implementation JPushPlugin
+
+#pragma mark- 外部接口
+-(void)stopPush:(CDVInvokedUrlCommand*)command{
+ [[UIApplication sharedApplication]unregisterForRemoteNotifications];
+}
+
+-(void)resumePush:(CDVInvokedUrlCommand*)command{
+ [(AppDelegate*)[UIApplication sharedApplication].delegate registerForRemoteNotification];
+}
+
+-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
+ NSNumber *result = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications] ? @(0) : @(1);
+ [self handleResultWithValue: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 ");
+ SharedJPushPlugin = self;
+}
+
+#else
+
+- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
+ NSLog(@"### initWithWebView ");
+ if (self=[super initWithWebView:theWebView]) {
+ }
+ return self;
+}
+
+#endif
+
+-(void)jpushFireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.%@',%@)", eventName, jsString]];
+ });
+}
+
+-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
+ NSString *alias = [command argumentAtIndex:0];
+ NSArray *tags = [command argumentAtIndex:1];
+ [JPUSHService setTags:[NSSet setWithArray:tags]
+ alias:alias
+ callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
+ object:self];
+}
+
+-(void)setTags:(CDVInvokedUrlCommand *)command{
+ NSArray *tags = command.arguments;
+ [JPUSHService setTags:[NSSet setWithArray:tags]
+ callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
+ object:self];
+}
+
+-(void)setAlias:(CDVInvokedUrlCommand *)command{
+ NSString *alias = [command argumentAtIndex:0];
+ [JPUSHService setAlias:alias
+ callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
+ object:self];
+}
+
+-(void)getRegistrationID:(CDVInvokedUrlCommand*)command{
+ NSString* registrationID = [JPUSHService registrationID];
+ [self handleResultWithValue:registrationID command:command];
+}
+
+-(void)startLogPageView:(CDVInvokedUrlCommand*)command{
+ NSString * pageName = [command argumentAtIndex:0];
+ [JPUSHService startLogPageView:pageName];
+}
+
+-(void)stopLogPageView:(CDVInvokedUrlCommand*)command{
+ NSString * pageName = [command argumentAtIndex:0];
+ [JPUSHService stopLogPageView:pageName];
+}
+
+-(void)beginLogPageView:(CDVInvokedUrlCommand*)command{
+ NSString *pageName = [command argumentAtIndex:0];
+ NSNumber *duration = [command argumentAtIndex:1];
+ [JPUSHService beginLogPageView:pageName duration:duration.intValue];
+}
+
+-(void)setBadge:(CDVInvokedUrlCommand*)command{
+ NSNumber *badge = [command argumentAtIndex:0];
+ [JPUSHService setBadge:badge.intValue];
+}
+
+-(void)resetBadge:(CDVInvokedUrlCommand*)command{
+ [JPUSHService resetBadge];
+}
+
+-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command{
+ NSNumber *badge = [command argumentAtIndex:0];
+ [UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
+}
+
+-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand *)command {
+ NSInteger num = [UIApplication sharedApplication].applicationIconBadgeNumber;
+ NSNumber *number = [NSNumber numberWithInteger:num];
+ [self handleResultWithValue: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{
+ NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more");
+
+ NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
+ NSString *alert = [command argumentAtIndex:1];
+ NSNumber *badge = [command argumentAtIndex:2];
+ NSString *idKey = [command argumentAtIndex:3];
+ NSDictionary *dict = [command argumentAtIndex:4];
+ [JPUSHService setLocalNotification:date alertBody:alert badge:badge alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
+}
+
+-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
+ NSString *identifier = [command argumentAtIndex:0];
+ JPushNotificationIdentifier *jpid = [JPushNotificationIdentifier new];
+ jpid.identifiers = @[identifier];
+ [JPUSHService removeNotification:jpid];
+}
+
+-(void)clearAllLocalNotifications:(CDVInvokedUrlCommand*)command{
+ [JPUSHService removeNotification:nil];
+}
+
+-(void)setLocation:(CDVInvokedUrlCommand*)command{
+ NSNumber *latitude = [command argumentAtIndex:0];
+ NSNumber *longitude = [command argumentAtIndex:1];
+ [JPUSHService setLatitude:latitude.doubleValue longitude:longitude.doubleValue];
+}
+
+-(void)getUserNotificationSettings:(CDVInvokedUrlCommand*)command{
+ if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
+ WEAK_SELF(weakSelf);
+ [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
+ NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+ dict[@"authorizationStatus"] = @(settings.authorizationStatus);
+ dict[@"soundSetting"] = @(settings.soundSetting);
+ dict[@"badgeSetting"] = @(settings.badgeSetting);
+ dict[@"alertSetting"] = @(settings.alertSetting);
+ dict[@"notificationCenterSetting"] = @(settings.notificationCenterSetting);
+ dict[@"lockScreenSetting"] = @(settings.lockScreenSetting);
+ dict[@"carPlaySetting"] = @(settings.carPlaySetting);
+ dict[@"alertStyle"] = @(settings.alertStyle);
+ [weakSelf handleResultWithValue:dict command:command];
+ }];
+ }else if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
+ UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
+ UIUserNotificationType type = settings.types;
+ NSNumber *number = [NSNumber numberWithInteger:type];
+ [self handleResultWithValue:number command:command];
+ }else{
+ UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
+ NSNumber *number = [NSNumber numberWithInteger:type];
+ [self handleResultWithValue:number command:command];
+ }
+}
+
+#pragma mark - ios 10 APIs
+
+-(void)addDismissActions:(CDVInvokedUrlCommand*)command{
+ [self addActions:command dismiss:YES];
+}
+
+-(void)addNotificationActions:(CDVInvokedUrlCommand*)command{
+ [self addActions:command dismiss:NO];
+}
+
+-(void)addActions:(CDVInvokedUrlCommand*)command dismiss:(BOOL)dimiss{
+ NSArray *actionsData = [command argumentAtIndex:0];
+ NSString *categoryId = [command argumentAtIndex:1];
+ NSMutableArray *actions = [NSMutableArray array];
+ for (NSDictionary *dict in actionsData) {
+ NSString *title = dict[@"title"];
+ NSString *identifier = dict[@"identifier"];
+ NSString *option = dict[@"option"];
+ NSString *type = dict[@"type"];
+ if ([type isEqualToString:@"textInput"]) {
+ NSString *textInputButtonTitle = dict[@"textInputButtonTitle"];
+ NSString *textInputPlaceholder = dict[@"textInputPlaceholder"];
+ UNTextInputNotificationAction *inputAction = [UNTextInputNotificationAction actionWithIdentifier:identifier title:title options:option.integerValue textInputButtonTitle:textInputButtonTitle textInputPlaceholder:textInputPlaceholder];
+ [actions addObject:inputAction];
+ }else{
+ UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:title title:title options:option.integerValue];
+ [actions addObject:action];
+ }
+ }
+ UNNotificationCategory *category;
+ if (dimiss) {
+ category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];
+ }else{
+ category = [UNNotificationCategory categoryWithIdentifier:categoryId actions:actions intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
+ }
+ [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObject:category]];
+}
+
+#pragma mark - 内部方法
+
++(void)setupJPushSDK:(NSDictionary*)userInfo{
+ NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
+ if (plistPath == nil) {
+ NSLog(@"error: PushConfig.plist not found");
+ assert(0);
+ }
+
+ NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
+ NSString *appkey = [plistData valueForKey:JPushConfig_Appkey];
+ NSString *channel = [plistData valueForKey:JPushConfig_Channel];
+ NSNumber *isProduction = [plistData valueForKey:JPushConfig_IsProduction];
+ NSNumber *isIDFA = [plistData valueForKey:JPushConfig_IsIDFA];
+
+ NSString *advertisingId = nil;
+ if(isIDFA){
+ advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
+ }
+ [JPUSHService setupWithOption:userInfo
+ appKey:appkey
+ channel:channel
+ apsForProduction:[isProduction boolValue]
+ advertisingIdentifier:advertisingId];
+}
+
+#pragma mark 将参数返回给js
+-(void)handleResultWithValue:(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
+ };
+ [self jpushFireDocumentEvent:JPushDocumentEvent_SetTagsWithAlias jsString:[dict toJsonString]];
+}
+
+- (void)networkDidReceiveMessage:(NSNotification *)notification {
+ if (notification && notification.userInfo) {
+ [self jpushFireDocumentEvent:JPushDocumentEvent_ReceiveMessage jsString:[notification.userInfo toJsonString]];
+ }
+}
+
+@end
diff --git a/src/ios/PushConfig.plist b/src/ios/PushConfig.plist
index 99b470f..3dc78da 100644
--- a/src/ios/PushConfig.plist
+++ b/src/ios/PushConfig.plist
@@ -2,9 +2,9 @@
- APP_KEY
+ Appkey
- CHANNEL
+ Channel
Subscription
IsProduction
diff --git a/src/ios/lib/JPUSHService.h b/src/ios/lib/JPUSHService.h
index f552234..e5424a3 100644
--- a/src/ios/lib/JPUSHService.h
+++ b/src/ios/lib/JPUSHService.h
@@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
*/
-#define JPUSH_VERSION_NUMBER 2.1.9
+#define JPUSH_VERSION_NUMBER 2.2.0
#import
diff --git a/src/ios/lib/jpush-ios-2.1.9.a b/src/ios/lib/jpush-ios-2.2.0.a
similarity index 51%
rename from src/ios/lib/jpush-ios-2.1.9.a
rename to src/ios/lib/jpush-ios-2.2.0.a
index 5bda39b..9e48b2d 100644
Binary files a/src/ios/lib/jpush-ios-2.1.9.a and b/src/ios/lib/jpush-ios-2.2.0.a differ
diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js
index a2e443e..a400df3 100644
--- a/www/JPushPlugin.js
+++ b/www/JPushPlugin.js
@@ -7,10 +7,10 @@ JPushPlugin.prototype.openNotification = {}
JPushPlugin.prototype.receiveNotification = {}
JPushPlugin.prototype.isPlatformIOS = function () {
- var isPlatformIOS = device.platform == 'iPhone'
- || device.platform == 'iPad'
- || device.platform == 'iPod touch'
- || device.platform == 'iOS'
+ var isPlatformIOS = device.platform == 'iPhone' ||
+ device.platform == 'iPad' ||
+ device.platform == 'iPod touch' ||
+ device.platform == 'iOS'
return isPlatformIOS
}
@@ -26,153 +26,103 @@ JPushPlugin.prototype.call_native = function (name, args, callback) {
// public methods
JPushPlugin.prototype.init = function () {
if (this.isPlatformIOS()) {
- var data = []
- this.call_native('initial', data, null)
+ this.call_native('initial', [], null)
} else {
- data = []
- this.call_native('init', data, null)
+ this.call_native('init', [], null)
}
}
JPushPlugin.prototype.getRegistrationID = function (callback) {
- try {
- var data = []
- this.call_native('getRegistrationID', [data], callback)
- } catch(exception) {
- console.log(exception)
- }
+ this.call_native('getRegistrationID', [], callback)
}
JPushPlugin.prototype.stopPush = function () {
- data = []
- this.call_native('stopPush', data, null)
+ this.call_native('stopPush', [], null)
}
JPushPlugin.prototype.resumePush = function () {
- data = []
- this.call_native('resumePush', data, null)
+ this.call_native('resumePush', [], null)
}
JPushPlugin.prototype.isPushStopped = function (callback) {
- data = []
- this.call_native('isPushStopped', data, callback)
+ this.call_native('isPushStopped', [], callback)
}
// iOS methods
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
- try {
- if (tags == null) {
- this.setAlias(alias)
- return
- }
- if (alias == null) {
- this.setTags(tags)
- return
- }
- var arrayTagWithAlias = [tags]
- arrayTagWithAlias.unshift(alias)
- this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
- } catch(exception) {
- console.log(exception)
+ if (tags == null) {
+ this.setAlias(alias)
+ return
}
+ if (alias == null) {
+ this.setTags(tags)
+ return
+ }
+ var arrayTagWithAlias = [tags]
+ arrayTagWithAlias.unshift(alias)
+ this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
}
JPushPlugin.prototype.setTags = function (tags) {
- try {
- this.call_native('setTags', tags, null)
- } catch(exception) {
- console.log(exception)
- }
+ this.call_native('setTags', tags, null)
}
JPushPlugin.prototype.setAlias = function (alias) {
- try {
- this.call_native('setAlias', [alias], null)
- } catch(exception) {
- console.log(exception)
- }
+ this.call_native('setAlias', [alias], null)
}
JPushPlugin.prototype.setBadge = function (value) {
if (this.isPlatformIOS()) {
- try {
- this.call_native('setBadge', [value], null)
- } catch(exception) {
- console.log(exception)
- }
+ this.call_native('setBadge', [value], null)
}
}
JPushPlugin.prototype.resetBadge = function () {
if (this.isPlatformIOS()) {
- try {
- var data = []
- this.call_native('resetBadge', [data], null)
- } catch(exception) {
- console.log(exception)
- }
+ this.call_native('resetBadge', [], null)
}
}
JPushPlugin.prototype.setDebugModeFromIos = function () {
if (this.isPlatformIOS()) {
- var data = []
- this.call_native('setDebugModeFromIos', [data], null)
+ this.call_native('setDebugModeFromIos', [], null)
}
}
JPushPlugin.prototype.setLogOFF = function () {
if (this.isPlatformIOS()) {
- var data = []
- this.call_native('setLogOFF', [data], null)
+ this.call_native('setLogOFF', [], null)
}
}
JPushPlugin.prototype.setCrashLogON = function () {
if (this.isPlatformIOS()) {
- var data = []
- this.call_native('crashLogON', [data], null)
+ this.call_native('crashLogON', [], 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)
+ this.call_native('setLocalNotification', [delayTime, content, badge, notificationID, extras], null)
}
}
-JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (
- identifierKey) {
+JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (identifierKey) {
if (this.isPlatformIOS()) {
- var data = [identifierKey]
- this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
+ this.call_native('deleteLocalNotificationWithIdentifierKey', [identifierKey], null)
}
}
JPushPlugin.prototype.clearAllLocalNotifications = function () {
if (this.isPlatformIOS()) {
- var data = []
- this.call_native('clearAllLocalNotifications', data, null)
+ this.call_native('clearAllLocalNotifications', [], 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)
+ this.call_native('setLocation', [latitude, longitude], null)
}
}
@@ -223,11 +173,11 @@ JPushPlugin.prototype.getUserNotificationSettings = function (callback) {
}
JPushPlugin.prototype.addDismissActions = function (actions, categoryId) {
- this.call_native('addDismissActions', [actions, categoryId])
+ this.call_native('addDismissActions', [actions, categoryId])
}
JPushPlugin.prototype.addNotificationActions = function (actions, categoryId) {
- this.call_native('addNotificationActions', [actions, categoryId])
+ this.call_native('addNotificationActions', [actions, categoryId])
}
// Android methods
@@ -239,61 +189,45 @@ JPushPlugin.prototype.setDebugMode = function (mode) {
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
if (device.platform == 'Android') {
- data = []
- this.call_native('setBasicPushNotificationBuilder', data, null)
+ this.call_native('setBasicPushNotificationBuilder', [], null)
}
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
if (device.platform == 'Android') {
- data = []
- this.call_native('setCustomPushNotificationBuilder', data, null)
+ this.call_native('setCustomPushNotificationBuilder', [], null)
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
- try {
- data = JSON.stringify(data)
- console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
- this.receiveMessage = JSON.parse(data)
- cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
- } catch(exception) {
- console.log('JPushPlugin:pushCallback ' + exception)
- }
+ data = JSON.stringify(data)
+ console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
+ this.receiveMessage = JSON.parse(data)
+ cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
- try {
- data = JSON.stringify(data)
- console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
- this.openNotification = JSON.parse(data)
- cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
- } catch(exception) {
- console.log(exception)
- }
+ data = JSON.stringify(data)
+ console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
+ this.openNotification = JSON.parse(data)
+ cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
- try {
- data = JSON.stringify(data)
- console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
- this.receiveNotification = JSON.parse(data)
- cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
- } catch(exception) {
- console.log(exception)
- }
+ data = JSON.stringify(data)
+ console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
+ this.receiveNotification = JSON.parse(data)
+ cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
}
JPushPlugin.prototype.clearAllNotification = function () {
if (device.platform == 'Android') {
- data = []
- this.call_native('clearAllNotification', data, null)
+ this.call_native('clearAllNotification', [], null)
}
}
JPushPlugin.prototype.clearNotificationById = function (notificationId) {
if (device.platform == 'Android') {
- data = []
this.call_native('clearNotificationById', [notificationId], null)
}
}
@@ -313,8 +247,7 @@ JPushPlugin.prototype.setDebugMode = function (mode) {
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
notificationID, broadcastTime, extras) {
if (device.platform == 'Android') {
- data = [builderId, content, title, notificationID, broadcastTime, extras]
- this.call_native('addLocalNotification', data, null)
+ this.call_native('addLocalNotification', [builderId, content, title, notificationID, broadcastTime, extras], null)
}
}
@@ -326,8 +259,7 @@ JPushPlugin.prototype.removeLocalNotification = function (notificationID) {
JPushPlugin.prototype.clearLocalNotifications = function () {
if (device.platform == 'Android') {
- data = []
- this.call_native('clearLocalNotifications', data, null)
+ this.call_native('clearLocalNotifications', [], null)
}
}
@@ -348,9 +280,9 @@ JPushPlugin.prototype.setStatisticsOpen = function (mode) {
}
/**
-* 用于在 Android 6.0 及以上系统,申请一些权限
-* 具体可看:http://docs.jpush.io/client/android_api/#android-60
-*/
+ * 用于在 Android 6.0 及以上系统,申请一些权限
+ * 具体可看:http://docs.jpush.io/client/android_api/#android-60
+ */
JPushPlugin.prototype.requestPermission = function () {
if (device.platform == 'Android') {
this.call_native('requestPermission', [], null)