TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jun 2017 |
Maintained by carlSQ.
AntNest 是吸收了 Go 语言的 Interface 模型的 iOS 的 App 模块化解耦编程的框架。
目前支持的模块的生命周期时间:
目前的支持的基本的系统事件:
在子模块中实现对应的方法,AntNest 就会自动的分发到对应的模块。
@implementation ANOrderAntRoom
ANT_EXPORT_ANTROOM()
+ (AntRoomLevel)antRoomLevel {
return 1;
}
+ (instancetype)createInstance:(NSDictionary *)launchOptions {
return [ANOrderAntRoom new];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"ANOrderAntRoom room");
return YES;
}
@end
AntNest 扩展事件分发是很方便的,举个简单的列子分发推送事件(AntNest 已经这个事件接口)
@protocol ANRemotePushEvent <NSObject>
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler ;
@end
@interface AntNest (ANRemotePushEvent)<ANRemotePushEvent>
@end
[[AntNest sharedAntNest] registerProtocolEvent:@protocol(ANRemotePushEvent)];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
[[AntNest sharedAntNest] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
ANT_EXPORT_ANTROOM()
实现 AntRoomProtocol 协议
antRoomLevel 表示模块的初始化优先级
+ (AntRoomLevel)antRoomLevel {
return 1;
}
+ (instancetype)createInstance:(NSDictionary *)launchOptions {
return [ANOrderAntRoom new];
}
模块间的通讯是通过 AntChannel 进行通讯,里面传递的都是实现 AntProtocol 协议对象。
假如我们要获取一个服务支持如下功能
@property(nonatomic, strong) NSString *orderID;
@property(nonatomic, strong) NSString *customerName;
@property(nonatomic, strong) NSString *shopName;
- (void)payOrder;
自定义一个 Protocol 获取服务实例
@protocol ANOrderDetailProtocol<AntProtocol>
@property(nonatomic, strong) NSString *orderID;
@property(nonatomic, strong) NSString *customerName;
@property(nonatomic, strong) NSString *shopName;
- (void)payOrder;
@end
...
id<ANOrderDetailProtocol> orderDetail = ANT_CHANNEL(ANOrderDetailProtocol, [[ANAntDes alloc] initWith:@"ANOrderDetailAnt"])
AntChannel 中传递的都是 ant service,
ANT_EXPORT_ANT()
+ (AntType)antType {
return @"OrderDetailAnt";
}
+ (instancetype)createInstance:(id<ANOrderDetailDescriptionProtocol>)antDescription {
ANOrderDetailViewController *order = [ANOrderDetailViewController new];
order.title = antDescription.orderID;
order.customerName = antDescription.customerName;
order.shopName = antDescription.shopName;
return order;
}
AntNest is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AntNest"
AntNest is available under the MIT license. See the LICENSE file for more info.