mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-02-20 20:22:50 +08:00
升级ios 库到 2.1.0
This commit is contained in:
parent
3d46fbc9ba
commit
3f9454edf3
34
README.md
34
README.md
@ -1,6 +1,17 @@
|
||||
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 文件夹名字 包名 应用名字
|
||||
@ -68,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文件中,这个文件的位置如下
|
||||
@ -188,5 +193,20 @@ l## JPush PhoneGap Plugin ##
|
||||
|
||||
[Android API详细说明](document/Android_detail_api.md)
|
||||
|
||||
###常见问题
|
||||
|
||||
####1. androd
|
||||
|
||||
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/)
|
@ -1,210 +1,224 @@
|
||||
|
||||
<!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);
|
||||
}
|
||||
}
|
||||
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 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();
|
||||
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>
|
||||
|
||||
|
||||
|
@ -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.6">
|
||||
version="2.1.0">
|
||||
|
||||
<name>JPush Plugin</name>
|
||||
<description>JPush for cordova plugin</description>
|
||||
@ -30,8 +30,8 @@
|
||||
<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.8.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" />
|
||||
|
@ -9,9 +9,9 @@
|
||||
#import "AppDelegate+JPush.h"
|
||||
#import <objc/runtime.h>
|
||||
#import "JPushPlugin.h"
|
||||
#import "APService.h"
|
||||
#import "JPUSHService.h"
|
||||
|
||||
static char launchNotificationKey;
|
||||
//static char launchNotificationKey;
|
||||
|
||||
@implementation AppDelegate (JPush)
|
||||
|
||||
@ -41,25 +41,42 @@ static char launchNotificationKey;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||||
[APService registerDeviceToken:deviceToken];
|
||||
[JPUSHService registerDeviceToken:deviceToken];
|
||||
}
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
|
||||
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
|
||||
}
|
||||
|
||||
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
|
||||
|
||||
[APService handleRemoteNotification:userInfo];
|
||||
[JPUSHService handleRemoteNotification:userInfo];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginReceiveNotification
|
||||
object:userInfo];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//delegate里不能声明变量,所以采用关联对象这种技术绕过这个限制
|
||||
//-(NSDictionary *)luanchOption{
|
||||
// return objc_getAssociatedObject(self, &launchNotificationKey);
|
||||
|
@ -22,4 +22,17 @@
|
||||
-(void)startLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
-(void)stopLogPageView:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
// 设置角标到服务器, 服务器下一次发消息时,会设置成这个值
|
||||
//本接口不会改变应用本地的角标值.
|
||||
-(void)setBadge:(CDVInvokedUrlCommand*)command;
|
||||
//相当于 [setBadge:0]
|
||||
-(void)resetBadge:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
|
||||
//改变应用本地的角标值.
|
||||
-(void)setApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
//获取应用本地的角标值.
|
||||
-(void)getApplicationIconBadgeNumber:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -7,335 +7,454 @@
|
||||
//
|
||||
|
||||
#import "JPushPlugin.h"
|
||||
#import "APService.h"
|
||||
#import "JPUSHService.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
|
||||
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 JMessageConfigFileName = @"PushConfig";
|
||||
|
||||
|
||||
static NSDictionary *_luanchOptions=nil;
|
||||
|
||||
@implementation JPushPlugin
|
||||
|
||||
|
||||
+(void)setLaunchOptions:(NSDictionary *)theLaunchOptions{
|
||||
_luanchOptions=theLaunchOptions;
|
||||
[APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||
UIUserNotificationTypeSound |
|
||||
UIUserNotificationTypeAlert)
|
||||
categories:nil];
|
||||
[APService setupWithOption:_luanchOptions];
|
||||
_luanchOptions=theLaunchOptions;
|
||||
[JPUSHService setDebugMode];
|
||||
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];
|
||||
}
|
||||
|
||||
//read appkey and channel from JMessageConfig.plist
|
||||
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JMessageConfigFileName 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 JMessageConfig.plist ");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
[JPUSHService setupWithOption:_luanchOptions appKey:appkey
|
||||
channel:channel apsForProduction:[isProduction boolValue] ];
|
||||
|
||||
}
|
||||
|
||||
-(void)initial:(CDVInvokedUrlCommand*)command{
|
||||
//do nithng,because Cordova plugin use lazy load mode.
|
||||
|
||||
}
|
||||
- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView{
|
||||
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]];
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return self;
|
||||
-(void)stopPush:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[[UIApplication sharedApplication]unregisterForRemoteNotifications];
|
||||
}
|
||||
|
||||
-(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) {
|
||||
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
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
|
||||
UIUserNotificationTypeSound |
|
||||
UIUserNotificationTypeAlert)
|
||||
categories:nil];
|
||||
} else {
|
||||
//categories 必须为nil
|
||||
[APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
}
|
||||
#else
|
||||
//categories 必须为nil
|
||||
[JPUSHService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
|
||||
UIRemoteNotificationTypeSound |
|
||||
UIRemoteNotificationTypeAlert)
|
||||
categories:nil];
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(void)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
|
||||
result=@(0);
|
||||
}else{
|
||||
result=@(1);
|
||||
}
|
||||
CDVPluginResult * pushResult=[self pluginResultForValue:result];
|
||||
if (pushResult) {
|
||||
[self succeedWithPluginResult:pushResult withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-(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)isPushStopped:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
NSNumber *result;
|
||||
if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications ]) {
|
||||
result=@(0);
|
||||
}else{
|
||||
result=@(1);
|
||||
|
||||
-(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]];
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
if (!arguments||[arguments count]<2) {
|
||||
|
||||
NSLog(@"#### setTagsWithAlias param is less");
|
||||
return ;
|
||||
}
|
||||
NSString *alias=[arguments objectAtIndex:0];
|
||||
NSArray *arrayTags=[arguments objectAtIndex:1];
|
||||
|
||||
NSLog(@"#### setTagsWithAlias alias is %@, tags is %@",alias,arrayTags);
|
||||
|
||||
NSSet* set=[NSSet setWithArray:arrayTags];
|
||||
[JPUSHService setTags:set
|
||||
alias:alias
|
||||
callbackSelector:@selector(tagsWithAliasCallback:tags:alias:)
|
||||
object:self];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
-(void)setTags:(CDVInvokedUrlCommand *)command{
|
||||
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
NSString *tags=[arguments objectAtIndex:0];
|
||||
|
||||
NSLog(@"#### setTags %@",tags);
|
||||
|
||||
NSArray *array=[tags componentsSeparatedByString:@","];
|
||||
[JPUSHService setTags:[NSSet setWithArray:array]
|
||||
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];
|
||||
|
||||
|
||||
NSArray *arguments=[command arguments];
|
||||
NSLog(@"#### setAlias %@",arguments);
|
||||
[JPUSHService setAlias:[arguments objectAtIndex: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);
|
||||
|
||||
CDVPluginResult *result=[self pluginResultForValue:registrationID];
|
||||
if (result) {
|
||||
[self succeedWithPluginResult:result withCallbackID:command.callbackId];
|
||||
} else {
|
||||
[self failWithCallbackID:command.callbackId];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-(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;
|
||||
|
||||
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]];
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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]];
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
-(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];
|
||||
}
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"startLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex: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 objectAtIndex:0];
|
||||
if (pageName) {
|
||||
[APService stopLogPageView:pageName];
|
||||
}
|
||||
|
||||
NSArray *arguments=command.arguments;
|
||||
if (!arguments||[arguments count]<1) {
|
||||
NSLog(@"stopLogPageView argument error");
|
||||
return ;
|
||||
}
|
||||
NSString * pageName=[arguments objectAtIndex: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 objectAtIndex:0];
|
||||
int duration=[[arguments objectAtIndex:0]intValue];
|
||||
if (pageName) {
|
||||
[APService beginLogPageView:pageName duration:duration];
|
||||
}
|
||||
|
||||
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) {
|
||||
[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 objectAtIndex:0];
|
||||
[APService setBadge:[badge intValue]];
|
||||
NSArray *argument=command.arguments;
|
||||
if ([argument count]<1) {
|
||||
NSLog(@"setBadge argument error!");
|
||||
return;
|
||||
}
|
||||
NSNumber *badge=[argument objectAtIndex:0];
|
||||
[JPUSHService 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)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;
|
||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:num];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setDebugModeFromIos:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[JPUSHService setDebugMode];
|
||||
}
|
||||
|
||||
|
||||
|
||||
-(void)setLogOFF:(CDVInvokedUrlCommand*)command{
|
||||
|
||||
[JPUSHService setLogOFF];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)failWithCallbackID:(NSString *)callbackID {
|
||||
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
|
||||
[self.commandDelegate sendPluginResult:result callbackId: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];
|
||||
[self.commandDelegate sendPluginResult:result callbackId:callbackID];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
- (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;
|
||||
|
||||
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]];
|
||||
}
|
||||
return result;
|
||||
} 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 {
|
||||
|
||||
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(), ^{
|
||||
|
||||
NSError *error;
|
||||
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
|
||||
NSString *jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
|
||||
|
||||
//NSLog(@"%@",jsonString);
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.receiveMessage',%@)",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]];
|
||||
|
||||
|
||||
});
|
||||
|
||||
[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];
|
||||
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:
|
||||
case UIApplicationStateBackground:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
|
||||
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:
|
||||
case UIApplicationStateBackground:
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.commandDelegate evalJs:[NSString stringWithFormat:@"cordova.fireDocumentEvent('jpush.openNotification',%@)",jsonString]];
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>APP_KEY</key>
|
||||
<string></string>
|
||||
<key>CHANNEL</key>
|
||||
<string>Subscription</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>APP_KEY</key>
|
||||
<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.8
|
||||
|
||||
@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,4 +1,5 @@
|
||||
|
||||
|
||||
var JPushPlugin = function(){
|
||||
};
|
||||
|
||||
@ -43,9 +44,14 @@ JPushPlugin.prototype.beginLogPageView = function(pageName,duration){
|
||||
}
|
||||
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge){
|
||||
if(this.isPlatformIOS()){
|
||||
this.call_native( "setApplicationIconBadgeNumber",[badge],null);
|
||||
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{
|
||||
@ -328,3 +334,5 @@ if(!window.plugins.jPushPlugin){
|
||||
|
||||
module.exports = new JPushPlugin();
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user