Skip to content

Commit b46b1c5

Browse files
authored
Merge pull request #5 from lincode/dev
FRDURLRoutes add regiter(plistFile:) method
2 parents 1d9ce27 + 7259284 commit b46b1c5

8 files changed

Lines changed: 89 additions & 17 deletions

File tree

FRDIntent.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "FRDIntent"
4-
s.version = "0.10.0"
4+
s.version = "0.9.1"
55
s.summary = "FRDIntent can handle the call between view controller"
66

77
s.description = "FRDIntent has two components URLRoutes and Intent, using for calling view controllers inner app or outer app."

FRDIntent.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
A36FCC2A1D87F96700059523 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A36FCC281D87F96700059523 /* LaunchScreen.storyboard */; };
3434
A382FE421D951C96007099DE /* FRDRouteParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = A382FE411D951C96007099DE /* FRDRouteParameters.swift */; };
3535
A384541D1DA807B100835B70 /* FRDIntentRegisters.plist in Resources */ = {isa = PBXBuildFile; fileRef = A384541C1DA807B100835B70 /* FRDIntentRegisters.plist */; };
36+
A3EBF8B31DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist in Resources */ = {isa = PBXBuildFile; fileRef = A3EBF8B21DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist */; };
3637
/* End PBXBuildFile section */
3738

3839
/* Begin PBXContainerItemProxy section */
@@ -101,6 +102,7 @@
101102
A36FCC2B1D87F96700059523 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
102103
A382FE411D951C96007099DE /* FRDRouteParameters.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FRDRouteParameters.swift; sourceTree = "<group>"; };
103104
A384541C1DA807B100835B70 /* FRDIntentRegisters.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = FRDIntentRegisters.plist; sourceTree = "<group>"; };
105+
A3EBF8B21DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = FRDURLRoutesRegisters.plist; sourceTree = "<group>"; };
104106
/* End PBXFileReference section */
105107

106108
/* Begin PBXFrameworksBuildPhase section */
@@ -226,6 +228,7 @@
226228
A35919521D87FFB100EBFD1E /* ThirdViewController.h */,
227229
A35919531D87FFB100EBFD1E /* ThirdViewController.m */,
228230
A384541C1DA807B100835B70 /* FRDIntentRegisters.plist */,
231+
A3EBF8B21DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist */,
229232
A36FCC261D87F96700059523 /* Assets.xcassets */,
230233
A36FCC281D87F96700059523 /* LaunchScreen.storyboard */,
231234
A36FCC2B1D87F96700059523 /* Info.plist */,
@@ -375,6 +378,7 @@
375378
files = (
376379
A384541D1DA807B100835B70 /* FRDIntentRegisters.plist in Resources */,
377380
A36FCC2A1D87F96700059523 /* LaunchScreen.storyboard in Resources */,
381+
A3EBF8B31DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist in Resources */,
378382
A36FCC271D87F96700059523 /* Assets.xcassets in Resources */,
379383
);
380384
runOnlyForDeploymentPostprocessing = 0;

FRDIntent/Source/Intent/FRDControllerManager.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class FRDControllerManager: NSObject {
2424
- parameter url: The url to be registered.
2525
- parameter clazz: The clazz to be registered, and the clazz's view controller object will be launched while routed.
2626

27-
- returns: True if register success.
27+
- returns: True if it registers successfully.
2828
*/
2929
public func register(url: URL, clazz: AnyClass) -> Bool {
3030
return routeManager.register(url: url, clazz: clazz as! FRDIntentReceivable.Type)
@@ -35,7 +35,7 @@ public class FRDControllerManager: NSObject {
3535

3636
- parameter plistFile: The plistFile path.
3737

38-
- returns: True if register success.
38+
- returns: True if it registers successfully.
3939
*/
4040
public func registers(plistFile: String) -> Bool {
4141

@@ -134,7 +134,6 @@ public class FRDControllerManager: NSObject {
134134
if let destinationController = destination as? UIViewController {
135135
display.displayViewController(source: source, destination: destinationController)
136136
}
137-
138137
}
139138

140139
}

FRDIntent/Source/URLRoutes/FRDURLRoutes.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ public extension FRDURLRoutes {
7474
return (resultForRoute && resultForIntent)
7575
}
7676

77+
/**
78+
Registers with a plist file.
79+
80+
- parameter plistFile: The plistFile path.
81+
82+
- returns: True if it registers successfully.
83+
*/
84+
public func registers(plistFile: String) -> Bool {
85+
86+
guard let registers: NSDictionary = NSDictionary(contentsOfFile: plistFile) else {
87+
return false
88+
}
89+
90+
for (url, className) in registers {
91+
92+
guard let url = url as? String, let className = className as? String else {
93+
return false
94+
}
95+
96+
if let clazz = NSClassFromString(className) as? FRDIntentReceivable.Type {
97+
let result = register(url: URL(string: url)!, clazz: clazz)
98+
if !result {
99+
return false
100+
}
101+
}
102+
103+
}
104+
return true
105+
}
106+
77107
}
78108

79109
private extension UIApplication {

FRDIntentDemo/AppDelegate.m

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,18 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction
105105

106106
- (void)configurationRoutes {
107107

108-
// Internal call
108+
// Internal call register
109109
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/user/:userId"] clazz: [FirstViewController class]];
110110
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/story/:storyId"] clazz: [SecondViewController class]];
111111
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/user/:userId/story/:storyId"] clazz: [ThirdViewController class]];
112112

113+
// Internal call register by plist
113114
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"FRDIntentRegisters" ofType:@"plist"];
114115
[[FRDControllerManager sharedInstance] registersWithPlistFile:plistPath];
115116

116-
// External call
117+
118+
119+
// External call register
117120
[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString:@"/user/:userId/story/:storyId"]
118121
handler:^(NSDictionary<NSString*, id> *params)
119122
{
@@ -126,8 +129,14 @@ - (void)configurationRoutes {
126129
}
127130
}];
128131

129-
[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString: @"/story/:storyId"]
130-
clazz:[SecondViewController self]];
132+
133+
// External call register
134+
//[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString: @"/story/:storyId"]
135+
// clazz:[SecondViewController self]];
136+
137+
// External call register by plist
138+
NSString* routesPlistPath = [[NSBundle mainBundle] pathForResource:@"FRDURLRoutesRegisters" ofType:@"plist"];
139+
[[FRDURLRoutes sharedInstance] registersWithPlistFile:routesPlistPath];
131140
}
132141

133142
@end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>/user/:userId</key>
6+
<string>FirstViewController</string>
7+
<key>/story/:storyId</key>
8+
<string>SecondViewController</string>
9+
</dict>
10+
</plist>

FRDIntentDemo/MainViewController.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ - (void)gotoThirdViewController
7575

7676
#pragma mark - FRDIntentForResultSendable
7777

78-
- (void)onControllerResultWithRequestCode:(NSInteger)requestCode resultCode:(enum FRDResultCode)code data:(FRDIntent *)intent
78+
- (void)onControllerResultWithRequestCode:(NSInteger)requestCode
79+
resultCode:(enum FRDResultCode)code
80+
data:(FRDIntent *)intent
7981
{
8082
if (requestCode == 1){
8183
if (code == FRDResultCodeOk) {

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,21 @@ FRDIntent/Intent 有如下优势:
6565

6666
#### 注册
6767

68+
通过代码注册:
69+
6870
```Swift
6971
let controllerManager = FRDControllerManager.sharedInstance
7072
controllerManager.register(URL(string: "/frodo/firstview")!, clazz: FirstViewController.self)
7173
```
7274

75+
通过 plist 文件批量注册:
76+
77+
```Swift
78+
let plistPath = Bundle.main.path(forResource: "FRDIntentRegisters", ofType: "plist")
79+
let controllerManager = FRDControllerManager.sharedInstance
80+
controllerManager.register(plistFile: plistPath)
81+
```
82+
7383
#### 通过指定类名启动 view controller
7484

7585
```Swift
@@ -93,12 +103,12 @@ FRDIntent/Intent 有如下优势:
93103
```Swift
94104
extension ViewController: FRDIntentForResultSendable {
95105

96-
func onControllerResult(_ requestCode: Int, resultCode: FRDResultCode, data: Intent) {
106+
func onControllerResult(requestCode: Int, resultCode: FRDResultCode, data: Intent) {
97107
if (requestCode == RequestText) {
98-
if (resultCode == .Ok) {
108+
if (resultCode == .ok) {
99109
let text = data.extra["text"]
100110
print("Successful confirm get from destination : \(text)")
101-
} else if (resultCode == .Canceled) {
111+
} else if (resultCode == .canceled) {
102112
let text = data.extra["text"]
103113
print("Canceled get from destination : \(text)")
104114
}
@@ -163,11 +173,19 @@ FRDIntent/URLRoutes 是为了使得 iOS 系统中这种基于 URL 的应用间
163173

164174
#### 注册
165175

166-
注册一个 ViewControler在第三方应用调起该 URL 时,会该启动该 view controller该 view controller 的进入动画为 Push 横滑进入方式
176+
通过代码注册一个 view controler在第三方应用调起该 URL 时,会该启动该 view controller该 view controller 的进入动画为 Push 横滑进入方式
167177

168178
```Swift
169-
let router = FRDURLRoutes.sharedInstance
170-
router.register(url: URL(string: "/story/:storyId")!, clazz: SecondViewController.self)
179+
let routes = FRDURLRoutes.sharedInstance
180+
routes.register(url: URL(string: "/story/:storyId")!, clazz: SecondViewController.self)
181+
```
182+
183+
通过 plist 文件批量注册,效果和上面通过代码注册一样注册的 view controller 进入动画都为 Push 横滑进入方式
184+
185+
```Swift
186+
let plistPath = Bundle.main.path(forResource: "FRDURLRoutesRegisters", ofType: "plist")
187+
let routes = FRDURLRoutes.sharedInstance
188+
routes.register(plistFile: plistPath)
171189
```
172190

173191
注册一个 block handler下面例子中的 block handler 中,用注册时的 URL 构造了一个 Intent,并将该 Intent 送出FRDControllerManager 会处理这个 Intent看是否有合适的 view controller 可以被启动
@@ -207,9 +225,9 @@ iOS 系统提供的通过 URL 调用另外一个应用功能本身就是使用
207225

208226
## FRDIntentDemo
209227

210-
FRDIntentDemo 对 FRDIntent 各种使用方法都做了演示
228+
FRDIntentDemo 对 FRDIntent 各种使用方法都做了演示FRDIntentDemo 使用 Objective-C 实现,这是为了演示 FRDIntent 虽然使用 Swift 完成,但是对 Objective-C 有良好的兼容
211229

212-
对于外部调用的演示,可以在模拟器的 Safari 的地址栏中输入 `frdintent://frdintent.com/user/123`。正常情况下,访问该 URL 将会启动 FRDIntentDemo,并进入 Firstview controller
230+
对于外部调用的演示,可以在模拟器的 Safari 的地址栏中输入 `frdintent://frdintent.com/user/123`。正常情况下,访问该 URL 将会启动 FRDIntentDemo,并进入 FirstViewController
213231

214232
## 单元测试
215233

0 commit comments

Comments
 (0)