添加PrefixHeader.pch:参见:(http://www.jianshu.com/p/a19bb67d705e)
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import "BeeHive.h"
#import "BHTimeProfiler.h"
#endif
=====================
Podfile:
platform :ios, '7.0'
target "TestBeehive" do
pod "BeeHive", '1.0.0'
end
=====================
在项目根目录下添加
--------------------
BeeHive.plist:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>moduleClasses</key>
<array>
<dict>
<key>moduleClass</key>
<string>TestService</string>
<key>moduleLevel</key>
<integer>1</integer>
</dict>
</array>
</dict>
</plist>
--------------------
BHService.plist:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>service</key>
<string>HomeServiceProtocol</string>
<key>impl</key>
<string>ViewController</string>
</dict>
</array>
</plist>
=====================
--------------------
AppDelegate.h
--------------------
#import <UIKit/UIKit.h>
@interface AppDelegate : BHAppDelegate <UIApplicationDelegate>
@end
--------------------
AppDelegate.m
--------------------
#import "AppDelegate.h"
#import "HomeServiceProtocol.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//[BHContext shareInstance].env = BHEnvironmentDev;
[BHContext shareInstance].application = application;
[BHContext shareInstance].launchOptions = launchOptions;
[BHContext shareInstance].moduleConfigName = @"BeeHive";//可选,默认为BeeHive.bundle/BeeHive.plist
[BHContext shareInstance].serviceConfigName = @"BHService";
[BeeHive shareInstance].enableExpection = YES;
[[BeeHive shareInstance] setContext:[BHContext shareInstance]];
[[BHTimeProfiler sharedTimeProfiler] recordEventTime:@"BeeHive::super start launch"];
[super application:application didFinishLaunchingWithOptions:launchOptions];
id<HomeServiceProtocol> homeVc = [[BeeHive shareInstance] createService:@protocol(HomeServiceProtocol)];
if ([homeVc isKindOfClass:[UIViewController class]]) {
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)homeVc];
[navCtrl setNavigationBarHidden:YES];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
}
return YES;
}
=====================
--------------------
ViewController.h
--------------------
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
--------------------
ViewController.m
--------------------
#import "ViewController.h"
#import "HomeServiceProtocol.h"
//BeeHiveService(HomeServiceProtocol,ViewController)
@interface ViewController()<HomeServiceProtocol>
@end
@implementation ViewController
-(instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)registerViewController:(UIViewController *)vc title:(NSString *)title iconName:(NSString *)iconName
{
// vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"Home.bundle/%@", iconName]];
// vc.tabBarItem.title = title;
//
// [self.registerViewControllers addObject:vc];
//
// self.viewControllers = self.registerViewControllers;
NSLog(@"test-======");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
=====================
--------------------
HomeServiceProtocol.h
--------------------
#import <Foundation/Foundation.h>
@protocol HomeServiceProtocol <NSObject, BHServiceProtocol>
-(void)registerViewController:(UIViewController *)vc title:(NSString *)title iconName:(NSString *)iconName;
@end
=====================
--------------------
TestService.h
--------------------
#import <Foundation/Foundation.h>
@interface TestService : NSObject
@end
--------------------
TestService.m
--------------------
#import "TestService.h"
#import "HomeServiceProtocol.h"
#import "ViewController.h"
@interface TestService()<BHModuleProtocol>
@end
@implementation TestService
//BH_EXPORT_MODULE(YES)
-(void)modInit:(BHContext *)context
{
switch (context.env) {
case BHEnvironmentDev:
//....初始化开发环境
break;
case BHEnvironmentProd:
//....初始化生产环境
default:
break;
}
}
- (void)modSetUp:(BHContext *)context
{
//[[BeeHive shareInstance]registerService:@protocol(HomeServiceProtocol) service:[ViewController class]];
NSLog(@"TradeModule setup");
}
=====================
=====================
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import "BeeHive.h"
#import "BHTimeProfiler.h"
#endif
=====================
Podfile:
platform :ios, '7.0'
target "TestBeehive" do
pod "BeeHive", '1.0.0'
end
=====================
在项目根目录下添加
--------------------
BeeHive.plist:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>moduleClasses</key>
<array>
<dict>
<key>moduleClass</key>
<string>TestService</string>
<key>moduleLevel</key>
<integer>1</integer>
</dict>
</array>
</dict>
</plist>
--------------------
BHService.plist:
--------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>service</key>
<string>HomeServiceProtocol</string>
<key>impl</key>
<string>ViewController</string>
</dict>
</array>
</plist>
=====================
--------------------
AppDelegate.h
--------------------
#import <UIKit/UIKit.h>
@interface AppDelegate : BHAppDelegate <UIApplicationDelegate>
@end
--------------------
AppDelegate.m
--------------------
#import "AppDelegate.h"
#import "HomeServiceProtocol.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//[BHContext shareInstance].env = BHEnvironmentDev;
[BHContext shareInstance].application = application;
[BHContext shareInstance].launchOptions = launchOptions;
[BHContext shareInstance].moduleConfigName = @"BeeHive";//可选,默认为BeeHive.bundle/BeeHive.plist
[BHContext shareInstance].serviceConfigName = @"BHService";
[BeeHive shareInstance].enableExpection = YES;
[[BeeHive shareInstance] setContext:[BHContext shareInstance]];
[[BHTimeProfiler sharedTimeProfiler] recordEventTime:@"BeeHive::super start launch"];
[super application:application didFinishLaunchingWithOptions:launchOptions];
id<HomeServiceProtocol> homeVc = [[BeeHive shareInstance] createService:@protocol(HomeServiceProtocol)];
if ([homeVc isKindOfClass:[UIViewController class]]) {
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)homeVc];
[navCtrl setNavigationBarHidden:YES];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
}
return YES;
}
=====================
--------------------
ViewController.h
--------------------
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
--------------------
ViewController.m
--------------------
#import "ViewController.h"
#import "HomeServiceProtocol.h"
//BeeHiveService(HomeServiceProtocol,ViewController)
@interface ViewController()<HomeServiceProtocol>
@end
@implementation ViewController
-(instancetype)init
{
self = [super init];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)registerViewController:(UIViewController *)vc title:(NSString *)title iconName:(NSString *)iconName
{
// vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"Home.bundle/%@", iconName]];
// vc.tabBarItem.title = title;
//
// [self.registerViewControllers addObject:vc];
//
// self.viewControllers = self.registerViewControllers;
NSLog(@"test-======");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
=====================
--------------------
HomeServiceProtocol.h
--------------------
#import <Foundation/Foundation.h>
@protocol HomeServiceProtocol <NSObject, BHServiceProtocol>
-(void)registerViewController:(UIViewController *)vc title:(NSString *)title iconName:(NSString *)iconName;
@end
=====================
--------------------
TestService.h
--------------------
#import <Foundation/Foundation.h>
@interface TestService : NSObject
@end
--------------------
TestService.m
--------------------
#import "TestService.h"
#import "HomeServiceProtocol.h"
#import "ViewController.h"
@interface TestService()<BHModuleProtocol>
@end
@implementation TestService
//BH_EXPORT_MODULE(YES)
-(void)modInit:(BHContext *)context
{
switch (context.env) {
case BHEnvironmentDev:
//....初始化开发环境
break;
case BHEnvironmentProd:
//....初始化生产环境
default:
break;
}
}
- (void)modSetUp:(BHContext *)context
{
//[[BeeHive shareInstance]registerService:@protocol(HomeServiceProtocol) service:[ViewController class]];
NSLog(@"TradeModule setup");
}
=====================
=====================