Compare commits

...

11 Commits

Author SHA1 Message Date
huangminlinux 07c9b2b945 fix iOS10 remove local notification fail bug 2017-10-20 11:28:51 +08:00
huangminlinux 8811dfc002 update docs 2017-10-19 13:51:19 +08:00
Hevin 0ee5f8b1a0 Update iOS SDK to v3.0.7 2017-10-13 13:10:47 +08:00
Hevin 259ec0a03a Update API doc 2017-10-13 13:09:19 +08:00
Hevin 6283cb26f6 Remove deprecated method
setTagsWithAlias
2017-10-13 10:12:16 +08:00
Hevin 1c3228848b build: v3.2.7 2017-10-11 14:49:07 +08:00
huangminlinux 585e2a5084 fix open local notification to launch app event bug 2017-10-11 14:28:56 +08:00
huangminlinux c726477cfb remove jpush.startLocalNotification event in iOS docs 2017-10-11 11:29:40 +08:00
huangminlinux 3f00143a5a update doc remove startLocalNotification event 2017-10-11 11:26:46 +08:00
huangminlinux f5ea2b5b10 ios add jpush.receiveRegistrationId event 2017-10-11 11:15:13 +08:00
Hevin 266d0cb28f Add JPushEventReceiver in manifest 2017-09-28 10:22:40 +08:00
14 changed files with 760 additions and 748 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
# JPush PhoneGap / Cordova Plugin # JPush PhoneGap / Cordova Plugin
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin) [![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![release](https://img.shields.io/badge/release-3.2.5-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) [![release](https://img.shields.io/badge/release-3.2.8-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin) [![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
-13
View File
@@ -9,19 +9,6 @@
- [设置保留最近通知条数](#设置保留最近通知条数) - [设置保留最近通知条数](#设置保留最近通知条数)
- [本地通知](#本地通知) - [本地通知](#本地通知)
## 注册成功事件
### jpush.receiveRegistrationId
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
#### 代码示例
```js
document.addEventListener('jpush.receiveRegistrationId', function (event) {
console.log(event.registrationId)
}, false)
```
## 获取集成日志(同时适用于 iOS) ## 获取集成日志(同时适用于 iOS)
### API - setDebugMode ### API - setDebugMode
+17
View File
@@ -1,5 +1,6 @@
# 通用 API 说明(同时适用于 Android 和 iOS 系统) # 通用 API 说明(同时适用于 Android 和 iOS 系统)
- [注册成功事件](#注册成功事件)
- [停止与恢复推送服务](#停止与恢复推送服务) - [停止与恢复推送服务](#停止与恢复推送服务)
- [获取 RegistrationID](#获取-registrationid) - [获取 RegistrationID](#获取-registrationid)
- [设置别名与标签](#设置别名与标签) - [设置别名与标签](#设置别名与标签)
@@ -8,7 +9,23 @@
- [获取自定义消息推送内容](#获取自定义消息推送内容) - [获取自定义消息推送内容](#获取自定义消息推送内容)
- [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送) - [判断系统设置中是否允许当前应用推送](#判断系统设置中是否允许当前应用推送)
## 注册成功事件
### jpush.receiveRegistrationId
集成了 JPush SDK 的应用程序在第一次成功注册到 JPush 服务器时,JPush 服务器会给客户端返回一个唯一的该设备的标识 - RegistrationID。
就会触发这个事件(注意只有第一次会触发该事件,之后如果想要取到 registrationId,可以直接调用 *getRegistrationID* 方法)。
#### 代码示例
```js
document.addEventListener('jpush.receiveRegistrationId', function (event) {
console.log(event.registrationId)
}, false)
```
## 停止与恢复推送服务 ## 停止与恢复推送服务
### API - init ### API - init
调用此 API,用来开启 JPush SDK 提供的推送服务。 调用此 API,用来开启 JPush SDK 提供的推送服务。
-10
View File
@@ -437,9 +437,7 @@ window.JPush.clearAllLocalNotifications()
监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。 监听 [jpush.receiveNotification](#前台收到推送)、[jpush.openNotification](点击推送通知),获取推送内容后,通过获取到的 `__JPUSHNotificationKey` 字段([本地通知](#本地通知) 设置的 `notificationID`)来判断是本地通知,并处理。
### 点击本地通知横幅启动 App
监听 `jpush.startLocalNotification` 事件。
## 页面的统计 ## 页面的统计
@@ -718,18 +716,10 @@ window.JPush.getUserNotificationSettings(callback)
[iOS 7 以后后台收到远程通知](#后台收到推送) [iOS 7 以后后台收到远程通知](#后台收到推送)
### jpush.setTagsWithAlias
[设置标签别名回调](#返回值说明)
### jpush.receiveMessage ### jpush.receiveMessage
[获取自定义消息内容](#获取自定义消息内容) [获取自定义消息内容](#获取自定义消息内容)
### jpush.startLocalNotification
[点击本地通知横幅启动 App](#点击本地通知横幅启动-app)
### jpush.receiveLocalNotification ### jpush.receiveLocalNotification
[iOS 10 before 收到本地通知](#ios-10-before-收到本地通知) [iOS 10 before 收到本地通知](#ios-10-before-收到本地通知)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "jpush-phonegap-plugin", "name": "jpush-phonegap-plugin",
"version": "3.2.5", "version": "3.2.8",
"description": "JPush for cordova plugin", "description": "JPush for cordova plugin",
"cordova": { "cordova": {
"id": "jpush-phonegap-plugin", "id": "jpush-phonegap-plugin",
+9 -2
View File
@@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin" id="jpush-phonegap-plugin"
version="3.2.5"> version="3.2.8">
<name>JPush</name> <name>JPush</name>
<description>JPush for cordova plugin</description> <description>JPush for cordova plugin</description>
@@ -38,7 +38,7 @@
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" /> <source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<header-file src="src/ios/lib/JPUSHService.h" /> <header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-3.0.6.a" framework="true" /> <source-file src="src/ios/lib/jpush-ios-3.0.7.a" framework="true" />
<resource-file src="src/ios/JPushConfig.plist" /> <resource-file src="src/ios/JPushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" /> <framework src="CFNetwork.framework" weak="true" />
@@ -195,6 +195,13 @@
android:name="cn.jpush.android.service.DataProvider" android:name="cn.jpush.android.service.DataProvider"
android:exported="true" /> android:exported="true" />
<receiver android:name="cn.jiguang.cordova.push.JPushEventReceiver">
<intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
<category android:name="$PACKAGE_NAME"></category>
</intent-filter>
</receiver>
<!-- Required. Enable it you can get statistics data with channel --> <!-- Required. Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" /> <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" /> <meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
+1 -20
View File
@@ -527,24 +527,6 @@ public class JPushPlugin extends CordovaPlugin {
eventCallbackMap.put(sequence, callbackContext); eventCallbackMap.put(sequence, callbackContext);
} }
void setTagsWithAlias(JSONArray data, CallbackContext callbackContext) {
HashSet<String> tags = new HashSet<String>();
String alias;
try {
alias = data.getString(0);
JSONArray tagsArray = data.getJSONArray(1);
for (int i = 0; i < tagsArray.length(); i++) {
tags.add(tagsArray.getString(i));
}
JPushInterface.setAliasAndTags(mContext,
alias, tags, mTagWithAliasCallback);
callbackContext.success();
} catch (JSONException e) {
e.printStackTrace();
callbackContext.error("Error reading tagAlias JSON");
}
}
void getConnectionState(JSONArray data, CallbackContext callback) { void getConnectionState(JSONArray data, CallbackContext callback) {
boolean isConnected = JPushInterface.getConnectionState(cordovaActivity.getApplicationContext()); boolean isConnected = JPushInterface.getConnectionState(cordovaActivity.getApplicationContext());
callback.success(String.valueOf(isConnected)); callback.success(String.valueOf(isConnected));
@@ -553,8 +535,7 @@ public class JPushPlugin extends CordovaPlugin {
/** /**
* 自定义通知行为,声音、震动、呼吸灯等。 * 自定义通知行为,声音、震动、呼吸灯等。
*/ */
void setBasicPushNotificationBuilder(JSONArray data, void setBasicPushNotificationBuilder(JSONArray data, CallbackContext callbackContext) {
CallbackContext callbackContext) {
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder( BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
this.cordova.getActivity()); this.cordova.getActivity());
builder.developerArg0 = "Basic builder 1"; builder.developerArg0 = "Basic builder 1";
+26 -7
View File
@@ -38,19 +38,28 @@
NSDictionary *_launchOptions; NSDictionary *_launchOptions;
-(void)applicationDidLaunch:(NSNotification *)notification{ -(void)applicationDidLaunch:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushSDKDidLoginNotification) name:kJPFNetworkDidLoginNotification object:nil];
if (notification) { if (notification) {
if (notification.userInfo) { if (notification.userInfo) {
NSDictionary *userInfo1 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo1.count > 0) { if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo1 repeats:YES]; [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:)
userInfo:[notification.userInfo
valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey] repeats:YES];
} }
NSDictionary *userInfo2 = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey]) {
if (userInfo2.count > 0) { UILocalNotification *localNotification = [notification.userInfo valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:userInfo2 repeats:YES];
NSDictionary* localNotificationEvent = @{@"content":localNotification.alertBody,
@"badge": @(localNotification.applicationIconBadgeNumber),
@"extras":localNotification.userInfo,
};
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(fireOpenNotification:) userInfo:localNotificationEvent repeats:YES];
} }
} }
[JPUSHService setDebugMode]; [JPUSHService setDebugMode];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
@@ -70,6 +79,11 @@ NSDictionary *_launchOptions;
[JPushPlugin setupJPushSDK:_launchOptions]; [JPushPlugin setupJPushSDK:_launchOptions];
} }
- (void)jpushSDKDidLoginNotification {
NSDictionary *event = @{@"registrationId": JPUSHService.registrationID};
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
}
-(void)registerForRemoteNotification{ -(void)registerForRemoteNotification{
if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) { if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
#ifdef NSFoundationVersionNumber_iOS_9_x_Max #ifdef NSFoundationVersionNumber_iOS_9_x_Max
@@ -141,7 +155,12 @@ NSDictionary *_launchOptions;
} }
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:notification.userInfo]; NSDictionary* localNotificationEvent = @{@"content":notification.alertBody,
@"badge": @(notification.applicationIconBadgeNumber),
@"extras":notification.userInfo,
};
[[NSNotificationCenter defaultCenter] postNotificationName:JPushDocumentEvent_ReceiveLocalNotification object:localNotificationEvent];
} }
- (void)applicationWillEnterForeground:(UIApplication *)application { - (void)applicationWillEnterForeground:(UIApplication *)application {
+1 -2
View File
@@ -27,7 +27,6 @@ static NSString *const JPushDocumentEvent_OpenNotification = @"openNoti
static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification"; static NSString *const JPushDocumentEvent_BackgroundNotification = @"backgroundNotification";
static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias"; static NSString *const JPushDocumentEvent_SetTagsWithAlias = @"setTagsWithAlias";
static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage"; static NSString *const JPushDocumentEvent_ReceiveMessage = @"receiveMessage";
static NSString *const JPushDocumentEvent_StartLocalNotification = @"startLocalNotification";
static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification"; static NSString *const JPushDocumentEvent_ReceiveLocalNotification = @"receiveLocalNotification";
static NSString *const JPushDocumentEvent_receiveRegistrationId = @"receiveRegistrationId";
-3
View File
@@ -17,8 +17,6 @@
//以下为js中可调用接口 //以下为js中可调用接口
//设置标签、别名 //设置标签、别名
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command;
-(void)setTags:(CDVInvokedUrlCommand*)command; -(void)setTags:(CDVInvokedUrlCommand*)command;
-(void)addTags:(CDVInvokedUrlCommand*)command; -(void)addTags:(CDVInvokedUrlCommand*)command;
-(void)deleteTags:(CDVInvokedUrlCommand*)command; -(void)deleteTags:(CDVInvokedUrlCommand*)command;
@@ -76,7 +74,6 @@
/* /*
* 以下为js中可监听到的事件 * 以下为js中可监听到的事件
* jpush.openNotification 点击推送消息启动或唤醒app * jpush.openNotification 点击推送消息启动或唤醒app
* jpush.setTagsWithAlias 设置标签、别名完成
* jpush.receiveMessage 收到自定义消息 * jpush.receiveMessage 收到自定义消息
* jpush.receiveNotification 前台收到推送 * jpush.receiveNotification 前台收到推送
* jpush.backgroundNotification 后台收到推送 * jpush.backgroundNotification 后台收到推送
+51 -22
View File
@@ -79,6 +79,10 @@
selector:@selector(networkDidReceiveMessage:) selector:@selector(networkDidReceiveMessage:)
name:kJPFNetworkDidReceiveMessageNotification name:kJPFNetworkDidReceiveMessageNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveLocalNotification:)
name:JPushDocumentEvent_ReceiveLocalNotification
object:nil];
} }
+(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{ +(void)fireDocumentEvent:(NSString*)eventName jsString:(NSString*)jsString{
@@ -87,23 +91,6 @@
}); });
} }
-(void)setTagsWithAlias:(CDVInvokedUrlCommand*)command{
NSString *alias = [command argumentAtIndex:0];
NSArray *tags = [command argumentAtIndex:1];
[JPUSHService setTags:[NSSet setWithArray:tags]
alias:alias
fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
CDVPluginResult *result;
if (iResCode == 0) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
} else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:nil];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}];
}
-(void)setTags:(CDVInvokedUrlCommand*)command { -(void)setTags:(CDVInvokedUrlCommand*)command {
NSDictionary* params = [command.arguments objectAtIndex:0]; NSDictionary* params = [command.arguments objectAtIndex:0];
NSNumber* sequence = params[@"sequence"]; NSNumber* sequence = params[@"sequence"];
@@ -364,14 +351,50 @@
} }
-(void)setLocalNotification:(CDVInvokedUrlCommand*)command{ -(void)setLocalNotification:(CDVInvokedUrlCommand*)command{
NSLog(@"ios 10 after please use UNNotificationRequest to set local notification, see apple doc to learn more"); NSNumber *delay = [command argumentAtIndex:0];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
NSString *alert = [command argumentAtIndex:1]; NSString *alert = [command argumentAtIndex:1];
NSNumber *badge = [command argumentAtIndex:2]; NSNumber *badge = [command argumentAtIndex:2];
NSString *idKey = [command argumentAtIndex:3]; NSString *idKey = [command argumentAtIndex:3];
NSDictionary *dict = [command argumentAtIndex:4]; NSDictionary *userInfo = [command argumentAtIndex:4];
[JPUSHService setLocalNotification:date alertBody:alert badge:badge.intValue alertAction:nil identifierKey:idKey userInfo:dict soundName:nil];
JPushNotificationContent *content = [[JPushNotificationContent alloc] init];
if (alert) {
content.body = alert;
}
if (badge) {
content.badge = badge;
}
if (userInfo) {
content.userInfo = userInfo;
}
JPushNotificationTrigger *trigger = [[JPushNotificationTrigger alloc] init];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
if (delay) {
trigger.timeInterval = [delay doubleValue];
}
} else {
if (delay) {
trigger.fireDate = [NSDate dateWithTimeIntervalSinceNow:[[command argumentAtIndex:0] intValue]];
}
}
JPushNotificationRequest *request = [[JPushNotificationRequest alloc] init];
request.content = content;
request.trigger = trigger;
if (idKey) {
request.requestIdentifier = idKey;
}
request.completionHandler = ^(id result) {
NSLog(@"result");
};
[JPUSHService addNotification:request];
} }
-(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{ -(void)deleteLocalNotificationWithIdentifierKey:(CDVInvokedUrlCommand*)command{
@@ -520,4 +543,10 @@
} }
} }
-(void)receiveLocalNotification:(NSNotification *)notification {
if (notification && notification.object) {
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveLocalNotification
jsString:[notification.object toJsonString]];
}
}
@end @end
+1 -1
View File
@@ -9,7 +9,7 @@
* Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved. * Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved.
*/ */
#define JPUSH_VERSION_NUMBER 3.0.6 #define JPUSH_VERSION_NUMBER 3.0.7
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
-14
View File
@@ -70,20 +70,6 @@ JPushPlugin.prototype.clearLocalNotifications = function () {
} }
} }
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias, successCallback, errorCallback) {
if (tags == null) {
this.setAlias(alias)
return
}
if (alias == null) {
this.setTags(tags)
return
}
var arrayTagWithAlias = [tags]
arrayTagWithAlias.unshift(alias)
this.callNative('setTagsWithAlias', arrayTagWithAlias, successCallback, errorCallback)
}
/** /**
* 设置标签。 * 设置标签。
* 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。 * 注意:该接口是覆盖逻辑,而不是增量逻辑。即新的调用会覆盖之前的设置。