Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pikacode committed Nov 28, 2016
2 parents 949177b + 9b543d8 commit d90f8ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<framework src="Security.framework" weak="true" />
<framework src="AudioToolbox.framework" weak="true" />
<framework src="MobileCoreServices.framework" weak="true" />
<framework src="UserNotifications.framework" weak="true" />
<framework src="libz.tbd"/>
<framework src="libsqlite3.0.tbd"/>
<framework src="libresolv.tbd"/>
Expand Down
4 changes: 4 additions & 0 deletions src/ios/Plugins/ConstantDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
36 changes: 32 additions & 4 deletions src/ios/Plugins/JMessageHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#import "JMessageHelper.h"
#import "ConstantDef.h"
#import <objc/runtime.h>
#import <UserNotifications/UserNotifications.h>

@interface JMessageHelper ()<JPUSHRegisterDelegate>

@end

@implementation JMessageHelper

Expand All @@ -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];

Expand Down
15 changes: 14 additions & 1 deletion src/ios/Plugins/JMessagePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d90f8ee

Please sign in to comment.