Skip to content

Commit

Permalink
cocoapods publish
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Jun 7, 2017
1 parent 789bdea commit ed80bd4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
Binary file added .CRRouter.podspec.swo
Binary file not shown.
2 changes: 1 addition & 1 deletion CRRouter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "CRRouter"
s.version = "0.0.3"
s.version = "0.0.4"
s.summary = "an simple iOS URL Router"

# This description is used to generate tags and improve search results.
Expand Down
23 changes: 16 additions & 7 deletions CRRouter/CRRouter/CRRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#import "CRRouter.h"

#define CRLock() dispatch_semaphore_wait(self->_lock, DISPATCH_TIME_FOREVER)
#define CRUnlock() dispatch_semaphore_signal(self->_lock)

@interface CRRouteNode()

- (BOOL)validateWithOriginParams:(NSDictionary *)params routeParams:(NSDictionary *)routeParams;
Expand Down Expand Up @@ -178,29 +181,29 @@ - (CRRouteNode *)addURLPatternForURL:(NSURL *)URL

- (void)addRouteNode:(CRRouteNode *)routeNode
{
dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER);
CRLock();
if(self.routesStorage[routeNode.scheme] == nil){
self.routesStorage[routeNode.scheme] = [[NSMutableDictionary alloc] init];
}
if (self.routesStorage[routeNode.scheme][routeNode.host] == nil) {
self.routesStorage[routeNode.scheme][routeNode.host] = [[NSMutableDictionary alloc] init];
}
self.routesStorage[routeNode.scheme][routeNode.host][routeNode.path] = routeNode;
dispatch_semaphore_signal(_lock);
CRUnlock();
}

- (CRRouteNode *)routeNodeForURL:(NSURL *)URL
{
dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER);
CRLock();
CRRouteNode * routeNode = self.routesStorage[URL.scheme][URL.host][URL.path];
dispatch_semaphore_signal(_lock);
CRUnlock();

return routeNode;
}

- (void)removeRouteNode:(CRRouteNode *)routeNode
{
dispatch_semaphore_wait(_lock, DISPATCH_TIME_FOREVER);
CRLock();

NSMutableDictionary *schemeRoutes = self.routesStorage[routeNode.scheme];
NSMutableDictionary *hostRoutes = schemeRoutes[routeNode.host];
Expand All @@ -209,7 +212,7 @@ - (void)removeRouteNode:(CRRouteNode *)routeNode
if(hostRoutes.count == 0) [schemeRoutes removeObjectForKey:routeNode.host];
if(schemeRoutes.count == 0) [self.routesStorage removeObjectForKey:routeNode.scheme];

dispatch_semaphore_signal(_lock);
CRUnlock();
}

#pragma mark - Utils
Expand Down Expand Up @@ -330,7 +333,13 @@ - (BOOL)openPageWithRouteParams:(NSDictionary *)routeParams
if(self.openHandler == nil)
return NO;

self.openHandler(routeParams);
if([NSThread isMainThread]){
self.openHandler(routeParams);
}else{
dispatch_async(dispatch_get_main_queue(), ^{
self.openHandler(routeParams);
});
}
return YES;
}

Expand Down
5 changes: 0 additions & 5 deletions CRRouter/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ - (IBAction)openRouteDeomo1:(id)sender

//or
// [CRRouter openURL:@"cr://goods/goodsDetail?p1=1"];

dispatch_block_t completionHandler = ^{

};
[CRRouter openURL:@"cr://goods/goodsDetail?goodsId=1" withParams:@{@"block" : completionHandler}];
}

- (IBAction)openRouteDemo2:(id)sender
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ CRRouteNode *routeNode = [CRRouteNode routeNodeWithURLScheme:@"cr" URLHost:@"goo
goodsVC.goodsId = routeParams[@"goodsId"];
UINavigationController *navigationVC = (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
[navigationVC pushViewController:goodsVC animated:YES];
}];
}];
```
如果实现了参数验证,如果这个block被调用,那肯定是参数验证通过了。

Expand Down

0 comments on commit ed80bd4

Please sign in to comment.