Skip to content

Commit

Permalink
Merge pull request #5 from lincode/dev
Browse files Browse the repository at this point in the history
FRDURLRoutes add regiter(plistFile:) method
  • Loading branch information
lincode authored Oct 16, 2016
2 parents 1d9ce27 + 7259284 commit b46b1c5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FRDIntent.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "FRDIntent"
s.version = "0.10.0"
s.version = "0.9.1"
s.summary = "FRDIntent can handle the call between view controller"

s.description = "FRDIntent has two components URLRoutes and Intent, using for calling view controllers inner app or outer app."
Expand Down
4 changes: 4 additions & 0 deletions FRDIntent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
A36FCC2A1D87F96700059523 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A36FCC281D87F96700059523 /* LaunchScreen.storyboard */; };
A382FE421D951C96007099DE /* FRDRouteParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = A382FE411D951C96007099DE /* FRDRouteParameters.swift */; };
A384541D1DA807B100835B70 /* FRDIntentRegisters.plist in Resources */ = {isa = PBXBuildFile; fileRef = A384541C1DA807B100835B70 /* FRDIntentRegisters.plist */; };
A3EBF8B31DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist in Resources */ = {isa = PBXBuildFile; fileRef = A3EBF8B21DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -226,6 +228,7 @@
A35919521D87FFB100EBFD1E /* ThirdViewController.h */,
A35919531D87FFB100EBFD1E /* ThirdViewController.m */,
A384541C1DA807B100835B70 /* FRDIntentRegisters.plist */,
A3EBF8B21DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist */,
A36FCC261D87F96700059523 /* Assets.xcassets */,
A36FCC281D87F96700059523 /* LaunchScreen.storyboard */,
A36FCC2B1D87F96700059523 /* Info.plist */,
Expand Down Expand Up @@ -375,6 +378,7 @@
files = (
A384541D1DA807B100835B70 /* FRDIntentRegisters.plist in Resources */,
A36FCC2A1D87F96700059523 /* LaunchScreen.storyboard in Resources */,
A3EBF8B31DB35D0100C7ED83 /* FRDURLRoutesRegisters.plist in Resources */,
A36FCC271D87F96700059523 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
5 changes: 2 additions & 3 deletions FRDIntent/Source/Intent/FRDControllerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FRDControllerManager: NSObject {
- parameter url: The url to be registered.
- parameter clazz: The clazz to be registered, and the clazz's view controller object will be launched while routed.

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

- parameter plistFile: The plistFile path.

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

Expand Down Expand Up @@ -134,7 +134,6 @@ public class FRDControllerManager: NSObject {
if let destinationController = destination as? UIViewController {
display.displayViewController(source: source, destination: destinationController)
}

}

}
Expand Down
30 changes: 30 additions & 0 deletions FRDIntent/Source/URLRoutes/FRDURLRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ public extension FRDURLRoutes {
return (resultForRoute && resultForIntent)
}

/**
Registers with a plist file.

- parameter plistFile: The plistFile path.

- returns: True if it registers successfully.
*/
public func registers(plistFile: String) -> Bool {

guard let registers: NSDictionary = NSDictionary(contentsOfFile: plistFile) else {
return false
}

for (url, className) in registers {

guard let url = url as? String, let className = className as? String else {
return false
}

if let clazz = NSClassFromString(className) as? FRDIntentReceivable.Type {
let result = register(url: URL(string: url)!, clazz: clazz)
if !result {
return false
}
}

}
return true
}

}

private extension UIApplication {
Expand Down
17 changes: 13 additions & 4 deletions FRDIntentDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction

- (void)configurationRoutes {

// Internal call
// Internal call register
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/user/:userId"] clazz: [FirstViewController class]];
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/story/:storyId"] clazz: [SecondViewController class]];
//[[FRDControllerManager sharedInstance] registerWithUrl: [NSURL URLWithString: @"/user/:userId/story/:storyId"] clazz: [ThirdViewController class]];

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

// External call


// External call register
[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString:@"/user/:userId/story/:storyId"]
handler:^(NSDictionary<NSString*, id> *params)
{
Expand All @@ -126,8 +129,14 @@ - (void)configurationRoutes {
}
}];

[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString: @"/story/:storyId"]
clazz:[SecondViewController self]];

// External call register
//[[FRDURLRoutes sharedInstance] registerWithUrl:[NSURL URLWithString: @"/story/:storyId"]
// clazz:[SecondViewController self]];

// External call register by plist
NSString* routesPlistPath = [[NSBundle mainBundle] pathForResource:@"FRDURLRoutesRegisters" ofType:@"plist"];
[[FRDURLRoutes sharedInstance] registersWithPlistFile:routesPlistPath];
}

@end
10 changes: 10 additions & 0 deletions FRDIntentDemo/FRDURLRoutesRegisters.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>/user/:userId</key>
<string>FirstViewController</string>
<key>/story/:storyId</key>
<string>SecondViewController</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion FRDIntentDemo/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ - (void)gotoThirdViewController

#pragma mark - FRDIntentForResultSendable

- (void)onControllerResultWithRequestCode:(NSInteger)requestCode resultCode:(enum FRDResultCode)code data:(FRDIntent *)intent
- (void)onControllerResultWithRequestCode:(NSInteger)requestCode
resultCode:(enum FRDResultCode)code
data:(FRDIntent *)intent
{
if (requestCode == 1){
if (code == FRDResultCodeOk) {
Expand Down
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,21 @@ FRDIntent/Intent 有如下优势:

#### 注册

通过代码注册:

```Swift
let controllerManager = FRDControllerManager.sharedInstance
controllerManager.register(URL(string: "/frodo/firstview")!, clazz: FirstViewController.self)
```

通过 plist 文件批量注册:

```Swift
let plistPath = Bundle.main.path(forResource: "FRDIntentRegisters", ofType: "plist")
let controllerManager = FRDControllerManager.sharedInstance
controllerManager.register(plistFile: plistPath)
```

#### 通过指定类名启动 view controller

```Swift
Expand All @@ -93,12 +103,12 @@ FRDIntent/Intent 有如下优势:
```Swift
extension ViewController: FRDIntentForResultSendable {

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

#### 注册

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

```Swift
let router = FRDURLRoutes.sharedInstance
router.register(url: URL(string: "/story/:storyId")!, clazz: SecondViewController.self)
let routes = FRDURLRoutes.sharedInstance
routes.register(url: URL(string: "/story/:storyId")!, clazz: SecondViewController.self)
```

通过 plist 文件批量注册,效果和上面通过代码注册一样注册的 view controller 进入动画都为 Push 横滑进入方式

```Swift
let plistPath = Bundle.main.path(forResource: "FRDURLRoutesRegisters", ofType: "plist")
let routes = FRDURLRoutes.sharedInstance
routes.register(plistFile: plistPath)
```

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

## FRDIntentDemo

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

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

## 单元测试

Expand Down

0 comments on commit b46b1c5

Please sign in to comment.