Skip to content

Commit

Permalink
[feature] notification among module
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLiYao committed Apr 11, 2018
1 parent bab659f commit 7d8fff1
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
@@ -1 +1,7 @@
# TinyPart
***
TinyPart是一个由Objective-C编写的面向服务的iOS模块化实践框架。
## 架构说明
## 特点
## 用法
## 开源许可证
24 changes: 24 additions & 0 deletions TinyPart.xcodeproj/project.pbxproj
Expand Up @@ -25,6 +25,9 @@
255E31B1207B6585002166CB /* TestRouter.m in Sources */ = {isa = PBXBuildFile; fileRef = 255E31B0207B6585002166CB /* TestRouter.m */; };
255E31B4207C5FC8002166CB /* TPMediator+Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 255E31B3207C5FC8002166CB /* TPMediator+Test.m */; };
255E31B6207CA4BD002166CB /* TinyPart.plist in Resources */ = {isa = PBXBuildFile; fileRef = 255E31B5207CA4BD002166CB /* TinyPart.plist */; };
25D15722207DA92A00D60E92 /* TinyPart.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 25D15721207DA92900D60E92 /* TinyPart.bundle */; };
25D15725207DAB6A00D60E92 /* TPNotificationCenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 25D15724207DAB6A00D60E92 /* TPNotificationCenter.m */; };
25D15728207DF46A00D60E92 /* ViewController2.m in Sources */ = {isa = PBXBuildFile; fileRef = 25D15727207DF46A00D60E92 /* ViewController2.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -63,6 +66,11 @@
255E31B2207C5FC8002166CB /* TPMediator+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TPMediator+Test.h"; sourceTree = "<group>"; };
255E31B3207C5FC8002166CB /* TPMediator+Test.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "TPMediator+Test.m"; sourceTree = "<group>"; };
255E31B5207CA4BD002166CB /* TinyPart.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = TinyPart.plist; sourceTree = "<group>"; };
25D15721207DA92900D60E92 /* TinyPart.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TinyPart.bundle; sourceTree = "<group>"; };
25D15723207DAB6A00D60E92 /* TPNotificationCenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TPNotificationCenter.h; sourceTree = "<group>"; };
25D15724207DAB6A00D60E92 /* TPNotificationCenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TPNotificationCenter.m; sourceTree = "<group>"; };
25D15726207DF46A00D60E92 /* ViewController2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController2.h; sourceTree = "<group>"; };
25D15727207DF46A00D60E92 /* ViewController2.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController2.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -96,6 +104,7 @@
isa = PBXGroup;
children = (
255E318E2079E613002166CB /* Classes */,
25D15720207DA76300D60E92 /* Resources */,
255E31782079E607002166CB /* AppDelegate.h */,
255E31792079E607002166CB /* AppDelegate.m */,
255E31A1207B1467002166CB /* TestModule.h */,
Expand All @@ -108,6 +117,8 @@
255E31B3207C5FC8002166CB /* TPMediator+Test.m */,
255E317B2079E607002166CB /* ViewController.h */,
255E317C2079E607002166CB /* ViewController.m */,
25D15726207DF46A00D60E92 /* ViewController2.h */,
25D15727207DF46A00D60E92 /* ViewController2.m */,
255E317E2079E607002166CB /* Main.storyboard */,
255E31812079E608002166CB /* Assets.xcassets */,
255E31832079E608002166CB /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -137,10 +148,20 @@
255E319F207A1595002166CB /* TPAppDelegate.m */,
255E31A4207B3FD9002166CB /* TPModuleProtocol.h */,
255E31A5207B3FE7002166CB /* TPServiceProtocol.h */,
25D15723207DAB6A00D60E92 /* TPNotificationCenter.h */,
25D15724207DAB6A00D60E92 /* TPNotificationCenter.m */,
);
path = Classes;
sourceTree = "<group>";
};
25D15720207DA76300D60E92 /* Resources */ = {
isa = PBXGroup;
children = (
25D15721207DA92900D60E92 /* TinyPart.bundle */,
);
path = Resources;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -200,6 +221,7 @@
files = (
255E31852079E608002166CB /* LaunchScreen.storyboard in Resources */,
255E31822079E608002166CB /* Assets.xcassets in Resources */,
25D15722207DA92A00D60E92 /* TinyPart.bundle in Resources */,
255E31B6207CA4BD002166CB /* TinyPart.plist in Resources */,
255E31802079E607002166CB /* Main.storyboard in Resources */,
);
Expand All @@ -223,7 +245,9 @@
255E31882079E608002166CB /* main.m in Sources */,
255E31AB207B4F20002166CB /* TPMediator.m in Sources */,
255E31942079E63B002166CB /* TinyPart.m in Sources */,
25D15725207DAB6A00D60E92 /* TPNotificationCenter.m in Sources */,
255E317A2079E607002166CB /* AppDelegate.m in Sources */,
25D15728207DF46A00D60E92 /* ViewController2.m in Sources */,
255E31A3207B1467002166CB /* TestModule.m in Sources */,
255E31912079E62F002166CB /* TPContext.m in Sources */,
);
Expand Down
46 changes: 46 additions & 0 deletions TinyPart/Base.lproj/Main.storyboard
Expand Up @@ -20,11 +20,57 @@
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nsN-Wg-4yT">
<rect key="frame" x="132" y="120" width="110" height="30"/>
<state key="normal" title="ViewController2"/>
<connections>
<segue destination="Use-XS-N4o" kind="show" id="C1T-BV-3NT"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="nsN-Wg-4yT" firstAttribute="top" secondItem="AT3-eq-QXZ" secondAttribute="bottom" constant="100" id="QS3-mI-RaA"/>
<constraint firstItem="nsN-Wg-4yT" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="vPG-hG-MJu"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="180" y="52"/>
</scene>
<!--View Controller2-->
<scene sceneID="U6B-8h-8QO">
<objects>
<viewController id="Use-XS-N4o" customClass="ViewController2" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="ZUN-iI-0sN"/>
<viewControllerLayoutGuide type="bottom" id="Vm0-Uh-BPl"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="ugM-Ja-Ccb">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TbF-9h-HCw">
<rect key="frame" x="170" y="142" width="34" height="30"/>
<state key="normal" title="back"/>
<connections>
<action selector="backButtonTapped:" destination="Use-XS-N4o" eventType="touchUpInside" id="RQi-ia-k7s"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="TbF-9h-HCw" firstAttribute="top" secondItem="ZUN-iI-0sN" secondAttribute="bottom" constant="122" id="V0w-IV-Tof"/>
<constraint firstItem="TbF-9h-HCw" firstAttribute="centerX" secondItem="ugM-Ja-Ccb" secondAttribute="centerX" id="acX-Er-Rxi"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="CN5-ED-gUl"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="UDW-Ad-ekr" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1044" y="134"/>
</scene>
</scenes>
</document>
6 changes: 3 additions & 3 deletions TinyPart/Classes/TPContext.m
Expand Up @@ -22,9 +22,9 @@ - (instancetype)init {
self = [super init];
if (self) {
_plistBundle = [NSBundle mainBundle];
_modulePlistFileName = @"TinyPart.plist";
_servicePlistFileName = @"TinyPart.plist";
_routerPlistFileName = @"TinyPart.plist";
_modulePlistFileName = @"TinyPart.bundle/TinyPart.plist";
_servicePlistFileName = @"TinyPart.bundle/TinyPart.plist";
_routerPlistFileName = @"TinyPart.bundle/TinyPart.plist";
}
return self;
}
Expand Down
7 changes: 5 additions & 2 deletions TinyPart/Classes/TPModuleManager.h
Expand Up @@ -7,12 +7,15 @@
//

#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
#import "TPModuleProtocol.h"

@class TPContext;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
@interface TPModuleManager : NSObject <UIApplicationDelegate, UNUserNotificationCenterDelegate>
#else
@interface TPModuleManager : NSObject <UIApplicationDelegate>
#endif

@property (copy, nonatomic, readonly) NSArray<id<TPModuleProtocol>> *allModules;

Expand Down
24 changes: 22 additions & 2 deletions TinyPart/Classes/TPModuleProtocol.h
Expand Up @@ -7,7 +7,9 @@
//

#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>

@class TPContext;
@class TPNotificationCenter;

#define TP_MODULE_ASYNC \
+ (BOOL)isAsync { \
Expand All @@ -17,12 +19,30 @@
+ (NSInteger)modulePriority { \
return priority;}

@class TPContext;
#define TP_MODULE_LEVEL(ModuleLevel) \
+ (TPModuleLevel)moduleLevel {\
return ModuleLevel;}


typedef NS_ENUM(NSUInteger, TPModuleLevel) {
TPModuleLevelBasic = 0,
TPModuleLevelMiddle,
TPModuleLevelTopout,
};

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
#import <UserNotifications/UserNotifications.h>
@protocol TPModuleProtocol <NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate>
#else
@protocol TPModuleProtocol <NSObject, UIApplicationDelegate>
#endif

@optional
+ (BOOL)isAsync;
+ (NSInteger)modulePriority;
+ (TPModuleLevel)moduleLevel;

- (void)moduleDidLoad:(TPContext *)context;

+ (TPNotificationCenter *)tp_notificationCenter;
@end
27 changes: 27 additions & 0 deletions TinyPart/Classes/TPNotificationCenter.h
@@ -0,0 +1,27 @@
//
// TPNotificationCenter.h
// TinyPart
//
// Created by Yao Li on 2018/4/11.
// Copyright © 2018年 yaoli. All rights reserved.
//

#import <Foundation/Foundation.h>

@class TPNotificationMaker;
@protocol TPModuleProtocol;

@interface TPNotificationCenter : NSObject
+ (instancetype)centerWithModule:(Class)module;

- (void)broadcastNotification:(void(^)(TPNotificationMaker *make))makerHandler;
- (void)reportNotification:(void(^)(TPNotificationMaker *make))makerHandler targetModule:(NSString *)moduleName;

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(NSString *)aName object:(id)anObject;
@end

@interface TPNotificationMaker : NSObject
- (TPNotificationMaker *(^)(NSString *name))name;
- (TPNotificationMaker *(^)(id object))object;
- (TPNotificationMaker *(^)(id userInfo))userInfo;
@end

0 comments on commit 7d8fff1

Please sign in to comment.