Skip to content

Commit 1eaf73a

Browse files
author
Hevin
committed
Merge branch 'dev'
2 parents 54b653e + 6c2bc20 commit 1eaf73a

File tree

4 files changed

+61
-60
lines changed

4 files changed

+61
-60
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# JPush PhoneGap / Cordova Plugin
22

33
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
4-
[![release](https://img.shields.io/badge/release-3.3.0-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
4+
[![release](https://img.shields.io/badge/release-3.4.0-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
55
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
66
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
77

@@ -11,12 +11,11 @@
1111
- 如需要短信验证码功能插件,可关注 [cordova-plugin-jsms](https://github.com/jpush/cordova-plugin-jsms)
1212
- 如需要统计分析功能插件,可关注 [cordova-plugin-janalytics](https://github.com/jpush/cordova-plugin-janalytics)
1313

14-
注意:目前插件暂未支持 cordova-android 7.0.0,因此在添加 android platform 时,请指定 7.0.0 以下版本,例如 6.4.0
14+
**注意**:插件从 v3.4.0 开始支持 cordova-android 7.0.0,因为 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。如果需要安装之前版本的插件,请先安装 v1.2.0 以下版本的 cordova-plugin-jcore,再安装插件
1515

1616
## Install
1717

1818
> 注意:
19-
>
2019
> - 应用的包名一定要和 APP_KEY 对应应用的包名一致,否则极光推送服务无法注册成功。
2120
> - 在使用 8 或以上版本的 Xcode 调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。
2221

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jpush-phonegap-plugin",
3-
"version": "3.3.0",
3+
"version": "3.4.0",
44
"description": "JPush for cordova plugin",
55
"cordova": {
66
"id": "jpush-phonegap-plugin",
@@ -23,7 +23,7 @@
2323
],
2424
"devDependencies": {
2525
"cordova-plugin-device": "*",
26-
"cordova-plugin-jcore": "*"
26+
"cordova-plugin-jcore": ">=1.2.0"
2727
},
2828
"author": "JiGuang",
2929
"license": "MIT",

plugin.xml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="jpush-phonegap-plugin"
5-
version="3.3.0">
5+
version="3.4.0">
66

77
<name>JPush</name>
88
<description>JPush for cordova plugin</description>
@@ -57,10 +57,6 @@
5757
<config-file target="*JPushConfig.plist" parent="Appkey">
5858
<string>$APP_KEY</string>
5959
</config-file>
60-
61-
<!-- <hook type="after_platform_add" src="hooks/iosEnablePush.js" />
62-
<hook type="after_plugin_install" src="hooks/iosEnablePush.js" />
63-
<hook type="before_plugin_uninstall" src="hooks/iosDisablePush.js" /> -->
6460
</platform>
6561

6662
<platform name="android">
@@ -70,8 +66,8 @@
7066
</feature>
7167
</config-file>
7268

73-
<config-file target="AndroidManifest.xml" parent="/manifest">
74-
<!-- Required 一些系统要求的权限,如访问网络等-->
69+
<config-file target="AndroidManifest.xml" parent="/manifest" mode="merge">
70+
<!-- Required 一些系统要求的权限,如访问网络等 -->
7571
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
7672
android:protectionLevel="signature" />
7773

@@ -90,8 +86,8 @@
9086
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
9187
</config-file>
9288

93-
<config-file target="AndroidManifest.xml" parent="/manifest/application">
94-
<!-- Required SDK核心功能-->
89+
<config-file target="AndroidManifest.xml" parent="/manifest/application" mode="merge">
90+
<!-- Required SDK核心功能 -->
9591
<activity android:name="cn.jpush.android.ui.PushActivity"
9692
android:theme="@android:style/Theme.Translucent.NoTitleBar"
9793
android:configChanges="orientation|keyboardHidden">
@@ -102,13 +98,13 @@
10298
</intent-filter>
10399
</activity>
104100

105-
<!-- Rich push 核心功能 since 2.0.6-->
101+
<!-- Rich push 核心功能 since 2.0.6 -->
106102
<activity android:name="cn.jpush.android.ui.PopWinActivity"
107103
android:theme="@style/MyDialogStyle"
108104
android:exported="false">
109105
</activity>
110106

111-
<!-- Required SDK核心功能-->
107+
<!-- Required SDK 核心功能 -->
112108
<service android:name="cn.jpush.android.service.DownloadService"
113109
android:enabled="true"
114110
android:exported="false">
@@ -148,7 +144,7 @@
148144
</intent-filter>
149145
</receiver>
150146

151-
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能-->
147+
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的 JPush 服务相互拉起的功能-->
152148
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
153149
<service android:name="cn.jpush.android.service.DaemonService"
154150
android:enabled="true"
@@ -159,7 +155,7 @@
159155
</intent-filter>
160156
</service>
161157

162-
<!-- User defined. For test only 用户自定义的广播接收器 -->
158+
<!-- 通知广播接收器 -->
163159
<receiver
164160
android:name="cn.jiguang.cordova.push.JPushReceiver"
165161
android:enabled="true">
@@ -196,26 +192,30 @@
196192
<meta-data android:name="JPUSH_APPKEY" android:value="$APP_KEY" />
197193
</config-file>
198194

199-
<source-file src="src/android/libs/jpush-android-3.1.1.jar" target-dir="libs" />
195+
<lib-file src="src/android/libs/jpush-android-3.1.1.jar" />
200196

201-
<source-file src="src/android/JPushReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
202-
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jiguang/cordova/push" />
203-
<source-file src="src/android/JPushEventReceiver.java" target-dir="src/cn/jiguang/cordova/push" />
197+
<source-file src="src/android/JPushReceiver.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
198+
<source-file src="src/android/JPushPlugin.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
199+
<source-file src="src/android/JPushEventReceiver.java" target-dir="app/src/main/java/cn/jiguang/cordova/push" />
204200

205-
<source-file src="src/android/res/drawable-hdpi/jpush_richpush_btn_selector.xml"
206-
target-dir="res/drawable" />
207-
<source-file src="src/android/res/drawable-hdpi/jpush_richpush_progressbar.xml"
208-
target-dir="res/drawable" />
201+
<resource-file src="src/android/res/drawable-hdpi/jpush_richpush_btn_selector.xml"
202+
target="res/drawable/jpush_richpush_btn_selector.xml" />
203+
<resource-file src="src/android/res/drawable-hdpi/jpush_richpush_progressbar.xml"
204+
target="res/drawable/jpush_richpush_progressbar.xml" />
209205

210-
<source-file src="src/android/res/drawable-hdpi/jpush_ic_richpush_actionbar_back.png"
211-
target-dir="res/drawable-hdpi" />
212-
<source-file src="src/android/res/drawable-hdpi/jpush_ic_richpush_actionbar_divider.png"
213-
target-dir="res/drawable-hdpi" />
206+
<resource-file src="src/android/res/drawable-hdpi/jpush_ic_richpush_actionbar_back.png"
207+
target="res/drawable-hdpi/jpush_ic_richpush_actionbar_back.png" />
208+
<resource-file src="src/android/res/drawable-hdpi/jpush_ic_richpush_actionbar_divider.png"
209+
target="res/drawable-hdpi/jpush_ic_richpush_actionbar_divider.png" />
214210

215-
<source-file src="src/android/res/layout/jpush_popwin_layout.xml" target-dir="res/layout" />
216-
<source-file src="src/android/res/layout/jpush_webview_layout.xml" target-dir="res/layout" />
217-
<source-file src="src/android/res/layout/test_notification_layout.xml" target-dir="res/layout" />
211+
<resource-file src="src/android/res/layout/jpush_popwin_layout.xml"
212+
target="res/layout/jpush_popwin_layout.xml" />
213+
<resource-file src="src/android/res/layout/jpush_webview_layout.xml"
214+
target="res/layout/jpush_webview_layout.xml" />
215+
<resource-file src="src/android/res/layout/test_notification_layout.xml"
216+
target="res/layout/test_notification_layout.xml" />
218217

219-
<source-file src="src/android/res/values/jpush_style.xml" target-dir="res/values" />
218+
<resource-file src="src/android/res/values/jpush_style.xml"
219+
target="res/values/jpush_style.xml" />
220220
</platform>
221221
</plugin>

src/ios/Plugins/AppDelegate+JPush.m

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ -(void)applicationDidLaunch:(NSNotification *)notification{
4040
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]];
4141
}];
4242

43-
if (notification) {
43+
if (notification != nil &&
44+
[[UIDevice currentDevice].systemVersion floatValue] < 10.0) {// iOS 10 以后通过 openNotification 这个回调触发事件。
4445
if (notification.userInfo) {
4546

4647
if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
@@ -58,19 +59,19 @@ -(void)applicationDidLaunch:(NSNotification *)notification{
5859
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]];
5960
}
6061
}
61-
62-
[JPUSHService setDebugMode];
63-
64-
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
65-
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
66-
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
67-
68-
_launchOptions = notification.userInfo;
69-
70-
if (![delay boolValue]) {
71-
[self startJPushSDK];
72-
}
7362
}
63+
64+
[JPUSHService setDebugMode];
65+
66+
NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"];
67+
NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
68+
NSNumber *delay = [plistData valueForKey:JPushConfig_Delay];
69+
70+
_launchOptions = notification.userInfo;
71+
72+
if (![delay boolValue]) {
73+
[self startJPushSDK];
74+
}
7475
}
7576

7677
-(void)startJPushSDK{
@@ -136,17 +137,12 @@ -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NS
136137
[JPUSHService handleRemoteNotification:userInfo];
137138
NSString *eventName;
138139
switch ([UIApplication sharedApplication].applicationState) {
139-
case UIApplicationStateInactive:
140-
eventName = JPushDocumentEvent_OpenNotification;
141-
break;
142-
case UIApplicationStateActive:
143-
eventName = JPushDocumentEvent_ReceiveNotification;
144-
break;
145-
case UIApplicationStateBackground:
146-
eventName = JPushDocumentEvent_BackgroundNotification;
147-
break;
148-
default:
149-
break;
140+
case UIApplicationStateBackground:
141+
eventName = JPushDocumentEvent_BackgroundNotification;
142+
break;
143+
default:
144+
eventName = JPushDocumentEvent_ReceiveNotification;
145+
break;
150146
}
151147

152148
[JPushPlugin fireDocumentEvent:eventName jsString:[[self jpushFormatAPNSDic:userInfo] toJsonString]];
@@ -156,7 +152,7 @@ -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NS
156152
}
157153

158154
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{
159-
NSMutableDictionary *userInfo = @[].mutableCopy;
155+
NSMutableDictionary *userInfo = @{}.mutableCopy;
160156

161157
if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
162158
userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo];
@@ -169,8 +165,14 @@ -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNot
169165
userInfo[@"identifier"] = notification.request.identifier;
170166
}
171167

172-
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
173168
completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert);
169+
170+
if ([userInfo[@"aps"][@"content-available"] isEqualToNumber:@(1)]) {// content-available 当用户开启后台推送是,防止触发两次事件
171+
return;
172+
}
173+
174+
[JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]];
175+
174176
}
175177

176178
-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{

0 commit comments

Comments
 (0)