diff --git a/BeeHive/BHAnnotation.h b/BeeHive/BHAnnotation.h index 8070d82..8d79c95 100644 --- a/BeeHive/BHAnnotation.h +++ b/BeeHive/BHAnnotation.h @@ -31,7 +31,7 @@ class BeeHive; char * k##name##_mod BeeHiveDATA(BeehiveMods) = ""#name""; #define BeeHiveService(servicename,impl) \ -class BeeHive;char * k##servicename##_service BeeHiveDATA(BeehiveServices) = "{ \""#servicename"\" : \""#impl"\"}"; +class BeeHive; char * k##servicename##_service BeeHiveDATA(BeehiveServices) = "{ \""#servicename"\" : \""#impl"\"}"; @interface BHAnnotation : NSObject diff --git a/BeeHive/BHAppDelegate.h b/BeeHive/BHAppDelegate.h index ee8093e..21b6f73 100644 --- a/BeeHive/BHAppDelegate.h +++ b/BeeHive/BHAppDelegate.h @@ -28,13 +28,13 @@ typedef void (^BHNotificationCompletionHandler)(); @property (nonatomic, strong) NSError *notificationsError; @property (nonatomic, strong) NSData *deviceToken; @property (nonatomic, strong) NSDictionary *userInfo; -@property (nonatomic, weak) BHNotificationResultHandler notificationResultHander; +@property (nonatomic, copy) 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, copy) BHNotificationPresentationOptionsHandler notificationPresentationOptionsHandler; +@property (nonatomic, copy) BHNotificationCompletionHandler notificationCompletionHandler; @property (nonatomic, strong) UNUserNotificationCenter *center; #endif @@ -43,32 +43,41 @@ typedef void (^BHNotificationCompletionHandler)(); @interface BHOpenURLItem : NSObject @property (nonatomic, strong) NSURL *openURL; -@property (nonatomic, strong) NSString *sourceApplication; +@property (nonatomic, copy) NSString *sourceApplication; +@property (nonatomic, strong) id annotation; @property (nonatomic, strong) NSDictionary *options; @end -typedef void (^shortcutItemCompletionHandler)(BOOL); +typedef void (^BHShortcutCompletionHandler)(BOOL); @interface BHShortcutItem : NSObject #if __IPHONE_OS_VERSION_MAX_ALLOWED > 80400 @property(nonatomic, strong) UIApplicationShortcutItem *shortcutItem; -@property(nonatomic, copy) shortcutItemCompletionHandler scompletionHandler; +@property(nonatomic, copy) BHShortcutCompletionHandler scompletionHandler; #endif @end -typedef void (^restorationHandler)(NSArray *); +typedef void (^BHUserActivityRestorationHandler)(NSArray *); @interface BHUserActivityItem : NSObject -@property (nonatomic, strong) NSString *userActivityType; +@property (nonatomic, copy) NSString *userActivityType; @property (nonatomic, strong) NSUserActivity *userActivity; @property (nonatomic, strong) NSError *userActivityError; -@property (nonatomic, strong) restorationHandler restorationHandler; +@property (nonatomic, copy) BHUserActivityRestorationHandler restorationHandler; +@end + +typedef void (^BHWatchReplyHandler)(NSDictionary *replyInfo); + +@interface BHWatchItem : NSObject + +@property (nonatomic, strong) NSDictionary *userInfo; +@property (nonatomic, copy) BHWatchReplyHandler replyHandler; @end diff --git a/BeeHive/BHAppDelegate.m b/BeeHive/BHAppDelegate.m index 16bc33b..0e37920 100644 --- a/BeeHive/BHAppDelegate.m +++ b/BeeHive/BHAppDelegate.m @@ -17,8 +17,12 @@ #import #endif - +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 +@interface BHAppDelegate () +#else @interface BHAppDelegate () +#endif + @end @@ -29,13 +33,17 @@ @implementation BHAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - [[BHModuleManager sharedManager] triggerEvent:BHMSetupEvent]; [[BHModuleManager sharedManager] triggerEvent:BHMInitEvent]; dispatch_async(dispatch_get_main_queue(), ^{ [[BHModuleManager sharedManager] triggerEvent:BHMSplashEvent]; }); +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 + if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0f) { + [UNUserNotificationCenter currentNotificationCenter].delegate = self; + } +#endif #ifdef DEBUG [[BHTimeProfiler sharedTimeProfiler] saveTimeProfileDataIntoFile:@"BeeHiveTimeProfiler"]; @@ -45,7 +53,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( } -#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80400 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80400 -(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler { @@ -84,11 +92,12 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceAppl { [[BeeHive shareInstance].context.openURLItem setOpenURL:url]; [[BeeHive shareInstance].context.openURLItem setSourceApplication:sourceApplication]; + [[BeeHive shareInstance].context.openURLItem setAnnotation:annotation]; [[BHModuleManager sharedManager] triggerEvent:BHMOpenURLEvent]; return YES; } -#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80400 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80400 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { @@ -136,10 +145,10 @@ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UI [[BHModuleManager sharedManager] triggerEvent:BHMDidReceiveLocalNotificationEvent]; } -#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80000 +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserActivity *)userActivity { - if([UIDevice currentDevice].systemVersion.floatValue > 8.0f){ + if([UIDevice currentDevice].systemVersion.floatValue >= 8.0f){ [[BeeHive shareInstance].context.userActivityItem setUserActivity: userActivity]; [[BHModuleManager sharedManager] triggerEvent:BHMDidUpdateUserActivityEvent]; } @@ -147,7 +156,7 @@ - (void)application:(UIApplication *)application didUpdateUserActivity:(NSUserAc - (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error { - if([UIDevice currentDevice].systemVersion.floatValue > 8.0f){ + if([UIDevice currentDevice].systemVersion.floatValue >= 8.0f){ [[BeeHive shareInstance].context.userActivityItem setUserActivityType: userActivityType]; [[BeeHive shareInstance].context.userActivityItem setUserActivityError: error]; [[BHModuleManager sharedManager] triggerEvent:BHMDidFailToContinueUserActivityEvent]; @@ -156,7 +165,7 @@ - (void)application:(UIApplication *)application didFailToContinueUserActivityWi - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { - if([UIDevice currentDevice].systemVersion.floatValue > 8.0f){ + if([UIDevice currentDevice].systemVersion.floatValue >= 8.0f){ [[BeeHive shareInstance].context.userActivityItem setUserActivity: userActivity]; [[BeeHive shareInstance].context.userActivityItem setRestorationHandler: restorationHandler]; [[BHModuleManager sharedManager] triggerEvent:BHMContinueUserActivityEvent]; @@ -166,12 +175,19 @@ - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserAct - (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType { - if([UIDevice currentDevice].systemVersion.floatValue > 8.0f){ + if([UIDevice currentDevice].systemVersion.floatValue >= 8.0f){ [[BeeHive shareInstance].context.userActivityItem setUserActivityType: userActivityType]; [[BHModuleManager sharedManager] triggerEvent:BHMWillContinueUserActivityEvent]; } return YES; } +- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(nullable NSDictionary *)userInfo reply:(void(^)(NSDictionary * __nullable replyInfo))reply { + if([UIDevice currentDevice].systemVersion.floatValue >= 8.0f){ + [BeeHive shareInstance].context.watchItem.userInfo = userInfo; + [BeeHive shareInstance].context.watchItem.replyHandler = reply; + [[BHModuleManager sharedManager] triggerEvent:BHMHandleWatchKitExtensionRequestEvent]; + } +} #endif #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { diff --git a/BeeHive/BHContext.h b/BeeHive/BHContext.h index fdc37a1..56d13da 100755 --- a/BeeHive/BHContext.h +++ b/BeeHive/BHContext.h @@ -55,6 +55,9 @@ typedef enum //user Activity Model @property (nonatomic, strong) BHUserActivityItem *userActivityItem; +//watch Model +@property (nonatomic, strong) BHWatchItem *watchItem; + //custom param @property (nonatomic, copy) NSDictionary *customParam; diff --git a/BeeHive/BHModuleManager.h b/BeeHive/BHModuleManager.h index 76dfc3a..6ac8bdd 100755 --- a/BeeHive/BHModuleManager.h +++ b/BeeHive/BHModuleManager.h @@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, BHModuleEventType) BHMContinueUserActivityEvent, BHMDidFailToContinueUserActivityEvent, BHMDidUpdateUserActivityEvent, + BHMHandleWatchKitExtensionRequestEvent, BHMDidCustomEvent = 1000 }; diff --git a/BeeHive/BHModuleManager.m b/BeeHive/BHModuleManager.m index 0b92199..f2391e4 100755 --- a/BeeHive/BHModuleManager.m +++ b/BeeHive/BHModuleManager.m @@ -16,6 +16,7 @@ #define kModuleInfoNameKey @"moduleClass" #define kModuleInfoLevelKey @"moduleLevel" #define kModuleInfoPriorityKey @"modulePriority" +#define kModuleInfoHasInstantiatedKey @"moduleHasInstantiated" static NSString *kSetupSelector = @"modSetUp:"; static NSString *kInitSelector = @"modInit:"; @@ -40,6 +41,7 @@ static NSString *kContinueUserActivitySelector = @"modContinueUserActivity:"; static NSString *kDidUpdateContinueUserActivitySelector = @"modDidUpdateContinueUserActivity:"; static NSString *kFailToContinueUserActivitySelector = @"modDidFailToContinueUserActivity:"; +static NSString *kHandleWatchKitExtensionRequestSelector = @"modHandleWatchKitExtensionRequest:"; static NSString *kAppCustomSelector = @"modDidCustomEvent:"; @@ -80,10 +82,16 @@ - (void)loadLocalModules NSDictionary *moduleList = [[NSDictionary alloc] initWithContentsOfFile:plistPath]; - NSArray *modulesArray = [moduleList objectForKey:kModuleArrayKey]; - - [self.BHModuleInfos addObjectsFromArray:modulesArray]; - + NSArray *modulesArray = [moduleList objectForKey:kModuleArrayKey]; + NSMutableDictionary *moduleInfoByClass = @{}.mutableCopy; + [self.BHModuleInfos enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + [moduleInfoByClass setObject:@1 forKey:[obj objectForKey:kModuleInfoNameKey]]; + }]; + [modulesArray enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if (!moduleInfoByClass[[obj objectForKey:kModuleInfoNameKey]]) { + [self.BHModuleInfos addObject:obj]; + } + }]; } - (void)registerDynamicModule:(Class)moduleClass @@ -149,18 +157,18 @@ - (void)registedAllModules NSString *classStr = [module objectForKey:kModuleInfoNameKey]; Class moduleClass = NSClassFromString(classStr); - - if (NSStringFromClass(moduleClass)) { + BOOL hasInstantiated = ((NSNumber *)[module objectForKey:kModuleInfoHasInstantiatedKey]).boolValue; + if (NSStringFromClass(moduleClass) && !hasInstantiated) { id moduleInstance = [[moduleClass alloc] init]; [tmpArray addObject:moduleInstance]; } }]; - [self.BHModules removeAllObjects]; +// [self.BHModules removeAllObjects]; [self.BHModules addObjectsFromArray:tmpArray]; - [self.BHModulesByEvent removeAllObjects]; + [self registerAllSystemEvents]; } @@ -260,6 +268,7 @@ - (void)addModuleFromObject:(id)object id moduleInstance = [[class alloc] init]; [self.BHModules addObject:moduleInstance]; + [moduleInfo setObject:@(YES) forKey:kModuleInfoHasInstantiatedKey]; [self.BHModules sortUsingComparator:^NSComparisonResult(id moduleInstance1, id moduleInstance2) { NSNumber *module1Level = @(BHModuleNormal); NSNumber *module2Level = @(BHModuleNormal); @@ -318,15 +327,38 @@ - (void)registerEvent:(NSInteger)eventType return; } NSNumber *eventTypeNumber = @(eventType); - if (![self.BHSelectorByEvent.allKeys containsObject:eventTypeNumber]) { + if (!self.BHSelectorByEvent[eventTypeNumber]) { [self.BHSelectorByEvent setObject:selectorStr forKey:eventTypeNumber]; } - if (![self.BHModulesByEvent.allKeys containsObject:eventTypeNumber]) { + if (!self.BHModulesByEvent[eventTypeNumber]) { [self.BHModulesByEvent setObject:@[].mutableCopy forKey:eventTypeNumber]; } NSMutableArray *eventModules = [self.BHModulesByEvent objectForKey:eventTypeNumber]; if (![eventModules containsObject:moduleInstance]) { [eventModules addObject:moduleInstance]; + [eventModules sortUsingComparator:^NSComparisonResult(id moduleInstance1, id moduleInstance2) { + NSNumber *module1Level = @(BHModuleNormal); + NSNumber *module2Level = @(BHModuleNormal); + if ([moduleInstance1 respondsToSelector:@selector(basicModuleLevel)]) { + module1Level = @(BHModuleBasic); + } + if ([moduleInstance2 respondsToSelector:@selector(basicModuleLevel)]) { + module2Level = @(BHModuleBasic); + } + if (module1Level.integerValue != module2Level.integerValue) { + return module1Level.integerValue > module2Level.integerValue; + } else { + NSInteger module1Priority = 0; + NSInteger module2Priority = 0; + if ([moduleInstance1 respondsToSelector:@selector(modulePriority)]) { + module1Priority = [moduleInstance1 modulePriority]; + } + if ([moduleInstance2 respondsToSelector:@selector(modulePriority)]) { + module2Priority = [moduleInstance2 modulePriority]; + } + return module1Priority < module2Priority; + } + }]; } } @@ -389,6 +421,7 @@ - (NSMutableArray *)BHModules @(BHMDidUpdateUserActivityEvent):kDidUpdateContinueUserActivitySelector, @(BHMQuickActionEvent):kQuickActionSelector, + @(BHMHandleWatchKitExtensionRequestEvent):kHandleWatchKitExtensionRequestSelector, @(BHMDidCustomEvent):kAppCustomSelector, }.mutableCopy; } diff --git a/BeeHive/BHModuleProtocol.h b/BeeHive/BHModuleProtocol.h index 1f2440f..bbba8e4 100755 --- a/BeeHive/BHModuleProtocol.h +++ b/BeeHive/BHModuleProtocol.h @@ -75,5 +75,7 @@ - (void)modDidUpdateContinueUserActivity:(BHContext *)context; +- (void)modHandleWatchKitExtensionRequest:(BHContext *)context; + - (void)modDidCustomEvent:(BHContext *)context; @end