From 9b543d80a937ec32406967898300fbfba8282628 Mon Sep 17 00:00:00 2001 From: pikacode Date: Mon, 28 Nov 2016 13:25:13 +0800 Subject: [PATCH] =?UTF-8?q?iOS=20-=20update=20=E9=80=82=E9=85=8D=20iOS=201?= =?UTF-8?q?0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin.xml | 1 + src/ios/Plugins/ConstantDef.h | 4 ++++ src/ios/Plugins/JMessageHelper.m | 36 ++++++++++++++++++++++++++++---- src/ios/Plugins/JMessagePlugin.m | 15 ++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/plugin.xml b/plugin.xml index c1d4542..2921738 100644 --- a/plugin.xml +++ b/plugin.xml @@ -57,6 +57,7 @@ + diff --git a/src/ios/Plugins/ConstantDef.h b/src/ios/Plugins/ConstantDef.h index 6a452b6..c963ba2 100644 --- a/src/ios/Plugins/ConstantDef.h +++ b/src/ios/Plugins/ConstantDef.h @@ -15,6 +15,10 @@ #define Plugin_Push_Name @"window.plugins.jPushPlugin" +#define kJPushPluginReceiveNotification @"JPushPluginReceiveNofication" +#define kJPushPluginiOS10ForegroundReceiveNotification @"kJPushPluginiOS10ForegroundReceiveNotification" +#define kJPushPluginiOS10ClickNotification @"kJPushPluginiOS10ClickNotification" + #define kJJMessageReceiveMessage @"kJJMessageReceiveMessage" #define kJJMessageSendMessageRespone @"kJJMessageSendMessageRespone" diff --git a/src/ios/Plugins/JMessageHelper.m b/src/ios/Plugins/JMessageHelper.m index d89fd18..b1eacb1 100644 --- a/src/ios/Plugins/JMessageHelper.m +++ b/src/ios/Plugins/JMessageHelper.m @@ -15,6 +15,11 @@ #import "JMessageHelper.h" #import "ConstantDef.h" #import +#import + +@interface JMessageHelper () + +@end @implementation JMessageHelper @@ -36,14 +41,37 @@ -(void)initJMessage:(NSDictionary*)launchOptions{ appKey:appkey channel:channel apsForProduction:NO category:nil]; - [JPUSHService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | - UIUserNotificationTypeSound | - UIUserNotificationTypeAlert) - categories:nil]; + + JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init]; + entity.types = UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound; + [JPUSHService registerForRemoteNotificationConfig:entity delegate:self]; + [self registerJPushStatusNotification]; +} + +-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler{ + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:notification.request.content.userInfo]; + + [userInfo setValue:kJPushPluginiOS10ForegroundReceiveNotification forKey:@"JPushNotificationType"]; + + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ForegroundReceiveNotification object:userInfo]; + + completionHandler(UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionAlert); } +-(void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler{ + NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:response.notification.request.content.userInfo]; + @try { + [userInfo setValue:[response valueForKey:@"userText"] forKey:@"userText"]; + } @catch (NSException *exception) { } + [userInfo setValue:response.actionIdentifier forKey:@"actionIdentifier"]; + [userInfo setValue:kJPushPluginiOS10ClickNotification forKey:@"JPushNotificationType"]; + [[NSNotificationCenter defaultCenter] postNotificationName:kJPushPluginiOS10ClickNotification object:userInfo]; + completionHandler(); +} + + - (void)registerJPushStatusNotification{ NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; diff --git a/src/ios/Plugins/JMessagePlugin.m b/src/ios/Plugins/JMessagePlugin.m index c42ad2c..8811417 100644 --- a/src/ios/Plugins/JMessagePlugin.m +++ b/src/ios/Plugins/JMessagePlugin.m @@ -91,8 +91,21 @@ -(void)initNotifications { [defaultCenter addObserver:self selector:@selector(networkDidReceiveNotification:) - name:kJJPushReceiveNotification + name:kJPushPluginReceiveNotification object:nil]; + + [defaultCenter addObserver:self + selector:@selector(networkDidReceiveNotification:) + name:kJPushPluginiOS10ForegroundReceiveNotification + object:nil]; + + [defaultCenter addObserver:self + selector:@selector(networkDidReceiveNotification:) + name:kJPushPluginiOS10ClickNotification + object:nil]; + + + [defaultCenter addObserver:self selector:@selector(unreadChanged:) name:kJJMessageUnreadChanged