diff --git a/README.md b/README.md index 63eed6e..bd8243b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 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) -[![release](https://img.shields.io/badge/release-3.3.0-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases) +[![release](https://img.shields.io/badge/release-3.4.0-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) [![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1) @@ -11,12 +11,11 @@ - 如需要短信验证码功能插件,可关注 [cordova-plugin-jsms](https://github.com/jpush/cordova-plugin-jsms) - 如需要统计分析功能插件,可关注 [cordova-plugin-janalytics](https://github.com/jpush/cordova-plugin-janalytics) -注意:目前插件暂未支持 cordova-android 7.0.0,因此在添加 android platform 时,请指定 7.0.0 以下版本,例如 6.4.0。 +**注意**:插件从 v3.4.0 开始支持 cordova-android 7.0.0,因为 cordova-android 7.0.0 修改了 Android 项目结构,因此不兼容之前的版本,升级前请务必注意。如果需要安装之前版本的插件,请先安装 v1.2.0 以下版本的 cordova-plugin-jcore,再安装插件。 ## Install > 注意: -> > - 应用的包名一定要和 APP_KEY 对应应用的包名一致,否则极光推送服务无法注册成功。 > - 在使用 8 或以上版本的 Xcode 调试 iOS 项目时,需要先在项目配置界面的 Capabilities 中打开 Push Notifications 开关。 diff --git a/package.json b/package.json index dec7419..f8ca70f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "3.3.0", + "version": "3.4.0", "description": "JPush for cordova plugin", "cordova": { "id": "jpush-phonegap-plugin", @@ -23,7 +23,7 @@ ], "devDependencies": { "cordova-plugin-device": "*", - "cordova-plugin-jcore": "*" + "cordova-plugin-jcore": ">=1.2.0" }, "author": "JiGuang", "license": "MIT", diff --git a/plugin.xml b/plugin.xml index 8f6dcc1..979967c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="3.4.0"> JPush JPush for cordova plugin @@ -57,10 +57,6 @@ $APP_KEY - - @@ -70,8 +66,8 @@ - - + + @@ -90,8 +86,8 @@ - - + + @@ -102,13 +98,13 @@ - + - + @@ -148,7 +144,7 @@ - + - + @@ -196,26 +192,30 @@ - + - - - + + + - - + + - - + + - - - + + + - + diff --git a/src/ios/Plugins/AppDelegate+JPush.m b/src/ios/Plugins/AppDelegate+JPush.m index fcc7026..e4b759e 100644 --- a/src/ios/Plugins/AppDelegate+JPush.m +++ b/src/ios/Plugins/AppDelegate+JPush.m @@ -40,7 +40,8 @@ NSDictionary *_launchOptions; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_receiveRegistrationId jsString:[event toJsonString]]; }]; - if (notification) { + if (notification != nil && + [[UIDevice currentDevice].systemVersion floatValue] < 10.0) {// iOS 10 以后通过 openNotification 这个回调触发事件。 if (notification.userInfo) { if ([notification.userInfo valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { @@ -58,19 +59,19 @@ NSDictionary *_launchOptions; [JPushPlugin fireDocumentEvent:JPushDocumentEvent_OpenNotification jsString:[localNotificationEvent toJsonString]]; } } - - [JPUSHService setDebugMode]; - - NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; - NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; - NSNumber *delay = [plistData valueForKey:JPushConfig_Delay]; - - _launchOptions = notification.userInfo; - - if (![delay boolValue]) { - [self startJPushSDK]; - } } + + [JPUSHService setDebugMode]; + + NSString *plistPath = [[NSBundle mainBundle] pathForResource:JPushConfig_FileName ofType:@"plist"]; + NSMutableDictionary *plistData = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath]; + NSNumber *delay = [plistData valueForKey:JPushConfig_Delay]; + + _launchOptions = notification.userInfo; + + if (![delay boolValue]) { + [self startJPushSDK]; + } } -(void)startJPushSDK{ @@ -136,17 +137,12 @@ NSDictionary *_launchOptions; [JPUSHService handleRemoteNotification:userInfo]; NSString *eventName; switch ([UIApplication sharedApplication].applicationState) { - case UIApplicationStateInactive: - eventName = JPushDocumentEvent_OpenNotification; - break; - case UIApplicationStateActive: - eventName = JPushDocumentEvent_ReceiveNotification; - break; - case UIApplicationStateBackground: - eventName = JPushDocumentEvent_BackgroundNotification; - break; - default: - break; + case UIApplicationStateBackground: + eventName = JPushDocumentEvent_BackgroundNotification; + break; + default: + eventName = JPushDocumentEvent_ReceiveNotification; + break; } [JPushPlugin fireDocumentEvent:eventName jsString:[[self jpushFormatAPNSDic:userInfo] toJsonString]]; @@ -156,7 +152,7 @@ NSDictionary *_launchOptions; } -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{ - NSMutableDictionary *userInfo = @[].mutableCopy; + NSMutableDictionary *userInfo = @{}.mutableCopy; if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) { userInfo = [self jpushFormatAPNSDic:notification.request.content.userInfo]; @@ -169,8 +165,14 @@ NSDictionary *_launchOptions; userInfo[@"identifier"] = notification.request.identifier; } - [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); + + if ([userInfo[@"aps"][@"content-available"] isEqualToNumber:@(1)]) {// content-available 当用户开启后台推送是,防止触发两次事件 + return; + } + + [JPushPlugin fireDocumentEvent:JPushDocumentEvent_ReceiveNotification jsString:[userInfo toJsonString]]; + } -(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{