Skip to content

Commit

Permalink
Merge pull request #73 from ZoMinster/UserNotifications_support
Browse files Browse the repository at this point in the history
User notifications support
  • Loading branch information
SoXeon authored May 10, 2017
2 parents 2901167 + 691ad30 commit 29a648a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
18 changes: 16 additions & 2 deletions BeeHive/BHAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,35 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
#endif


@interface BHAppDelegate : UIResponder <UIApplicationDelegate>

@end

typedef void (^notificationResultHandler)(UIBackgroundFetchResult);
typedef void (^BHNotificationResultHandler)(UIBackgroundFetchResult);
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
typedef void (^BHNotificationPresentationOptionsHandler)(UNNotificationPresentationOptions options);
typedef void (^BHNotificationCompletionHandler)();
#endif

@interface BHNotificationsItem : NSObject

@property (nonatomic, strong) NSError *notificationsError;
@property (nonatomic, strong) NSData *deviceToken;
@property (nonatomic, strong) NSDictionary *userInfo;
@property (nonatomic, assign) notificationResultHandler notificationResultHander;
@property (nonatomic, weak) BHNotificationResultHandler notificationResultHander;
@property (nonatomic, strong) UILocalNotification *localNotification;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@property (nonatomic, strong) UNNotification *notification;
@property (nonatomic, strong) UNNotificationResponse *notificationResponse;
@property (nonatomic, weak) BHNotificationPresentationOptionsHandler notificationPresentationOptionsHandler;
@property (nonatomic, weak) BHNotificationCompletionHandler notificationCompletionHandler;
@property (nonatomic, strong) UNUserNotificationCenter *center;
#endif

@end

Expand Down
20 changes: 20 additions & 0 deletions BeeHive/BHAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#import "BHModuleManager.h"
#import "BHTimeProfiler.h"

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
#endif


@interface BHAppDelegate ()

@end
Expand Down Expand Up @@ -168,6 +173,21 @@ - (BOOL)application:(UIApplication *)application willContinueUserActivityWithTyp
return YES;
}
#endif
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
[[BeeHive shareInstance].context.notificationsItem setNotification: notification];
[[BeeHive shareInstance].context.notificationsItem setNotificationPresentationOptionsHandler: completionHandler];
[[BeeHive shareInstance].context.notificationsItem setCenter:center];
[[BHModuleManager sharedManager] triggerEvent:BHMWillPresentNotificationEvent];
};

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
[[BeeHive shareInstance].context.notificationsItem setNotificationResponse: response];
[[BeeHive shareInstance].context.notificationsItem setNotificationCompletionHandler:completionHandler];
[[BeeHive shareInstance].context.notificationsItem setCenter:center];
[[BHModuleManager sharedManager] triggerEvent:BHMDidReceiveNotificationResponseEvent];
};
#endif

@end

Expand Down
2 changes: 2 additions & 0 deletions BeeHive/BHModuleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ typedef NS_ENUM(NSInteger, BHModuleEventType)
BHMDidRegisterForRemoteNotificationsEvent,
BHMDidReceiveRemoteNotificationEvent,
BHMDidReceiveLocalNotificationEvent,
BHMWillPresentNotificationEvent,
BHMDidReceiveNotificationResponseEvent,
BHMWillContinueUserActivityEvent,
BHMContinueUserActivityEvent,
BHMDidFailToContinueUserActivityEvent,
Expand Down
8 changes: 8 additions & 0 deletions BeeHive/BHModuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
static NSString *kDidRegisterForRemoteNotificationsSelector = @"modDidRegisterForRemoteNotifications:";
static NSString *kDidReceiveRemoteNotificationsSelector = @"modDidReceiveRemoteNotification:";
static NSString *kDidReceiveLocalNotificationsSelector = @"modDidReceiveLocalNotification:";
static NSString *kWillPresentNotificationSelector = @"modWillPresentNotification:";
static NSString *kDidReceiveNotificationResponseSelector = @"modDidReceiveNotificationResponse:";
static NSString *kWillContinueUserActivitySelector = @"modWillContinueUserActivity:";
static NSString *kContinueUserActivitySelector = @"modContinueUserActivity:";
static NSString *kDidUpdateContinueUserActivitySelector = @"modDidUpdateContinueUserActivity:";
Expand Down Expand Up @@ -162,6 +164,12 @@ - (void)triggerEvent:(BHModuleEventType)eventType
case BHMDidReceiveRemoteNotificationEvent:
[self handleModuleEvent:kDidReceiveRemoteNotificationsSelector];
break;
case BHMWillPresentNotificationEvent:
[self handleModuleEvent:kWillPresentNotificationSelector];
break;
case BHMDidReceiveNotificationResponseEvent:
[self handleModuleEvent:kDidReceiveNotificationResponseSelector];
break;

case BHMDidFailToRegisterForRemoteNotificationsEvent:
[self handleModuleEvent:kFailToRegisterForRemoteNotificationsSelector];
Expand Down
4 changes: 4 additions & 0 deletions BeeHive/BHModuleProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@

- (void)modDidReceiveLocalNotification:(BHContext *)context;

- (void)modWillPresentNotification:(BHContext *)context;

- (void)modDidReceiveNotificationResponse:(BHContext *)context;

- (void)modWillContinueUserActivity:(BHContext *)context;

- (void)modContinueUserActivity:(BHContext *)context;
Expand Down

0 comments on commit 29a648a

Please sign in to comment.