Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
GMRouter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMRouter
Commits
c3a5da24
Commit
c3a5da24
authored
Aug 13, 2020
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
f49f376c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
48 deletions
+57
-48
GMTableViewController.m
Example/GMRouter/GMTableViewController.m
+21
-8
GMViewController.m
Example/GMRouter/GMViewController.m
+3
-2
Podfile.lock
Example/Podfile.lock
+2
-2
GMRouter+gm.h
GMRouter/Classes/GMRouter+gm.h
+12
-12
GMRouter+gm.m
GMRouter/Classes/GMRouter+gm.m
+12
-16
UIResponder+router.h
GMRouter/Classes/UIResponder+router.h
+3
-3
UIResponder+router.m
GMRouter/Classes/UIResponder+router.m
+4
-5
No files found.
Example/GMRouter/GMTableViewController.m
View file @
c3a5da24
...
...
@@ -29,26 +29,39 @@
#pragma mark - Table view data source
-
(
NSInteger
)
numberOfSectionsInTableView
:
(
UITableView
*
)
tableView
{
#warning Incomplete implementation, return the number of sections
return
10
;
return
1
;
}
-
(
NSInteger
)
tableView
:
(
UITableView
*
)
tableView
numberOfRowsInSection
:
(
NSInteger
)
section
{
#warning Incomplete implementation, return the number of rows
return
1
;
return
10
;
}
-
(
UITableViewCell
*
)
tableView
:
(
UITableView
*
)
tableView
cellForRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
UITableViewCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
@"cell"
forIndexPath
:
indexPath
];
cell
.
textLabel
.
text
=
[
NSString
stringWithFormat
:
@"%点我跳---ld"
,
indexPath
.
row
];
if
(
indexPath
.
row
==
0
)
{
cell
.
textLabel
.
text
=
@"pushScheme"
;
}
else
if
(
indexPath
.
row
==
1
)
{
cell
.
textLabel
.
text
=
@"pushScheme:completeBlock"
;
}
else
if
(
indexPath
.
row
==
2
)
{
cell
.
textLabel
.
text
=
@"pushScheme: params:routerBlock"
;
}
else
{
cell
.
textLabel
.
text
=
[
NSString
stringWithFormat
:
@"%点我跳---ld"
,
indexPath
.
row
];
}
return
cell
;
}
-
(
void
)
tableView
:
(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
UIViewController
*
vc
=
[[
GMRouter
sharedInstance
]
pushScheme
:
@"common"
completeBlock
:
^
(
NSDictionary
*
_Nonnull
params
)
{
}];
if
(
indexPath
.
row
==
0
)
{
[[
GMRouter
sharedInstance
]
pushScheme
:
@"common"
];
}
else
if
(
indexPath
.
row
==
1
)
{
[[
GMRouter
sharedInstance
]
pushScheme
:
@"common"
completeBlock
:
NULL
];
}
else
if
(
indexPath
.
row
==
2
)
{
[[
GMRouter
sharedInstance
]
pushScheme
:
@"common"
params
:@{}
completeBlock
:^
(
NSDictionary
*
_Nonnull
params
)
{
NSLog
(
@"收到回调"
);
}];
}
}
...
...
Example/GMRouter/GMViewController.m
View file @
c3a5da24
...
...
@@ -39,8 +39,9 @@
// return YES;
// }
if
(
self
.
routerBlock
)
{
self
.
routerBlock
(@{
@"a"
:
@10
});
if
(
self
.
routerCompleteBlock
)
{
// self.routerBlock(@{@"a":@10});
self
.
routerCompleteBlock
(@{
@"a"
:
@10
});
}
return
YES
;
}
...
...
Example/Podfile.lock
View file @
c3a5da24
...
...
@@ -5,7 +5,7 @@ PODS:
- GMCache
- MagicalRecord
- MJExtension
- GMRouter (0.2.
4
):
- GMRouter (0.2.
6
):
- GMPhobos
- MJExtension
- MagicalRecord (2.3.2):
...
...
@@ -33,7 +33,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
GMCache: b78d8e46db864405e91d226ce640cc80d966c611
GMPhobos: 981b9c9509945eaa28b4ad6a5376eb78f3fd54b5
GMRouter:
1445202be8e6c80d04a9f8c1e38f9ebbec728abf
GMRouter:
b7411f9fef73aa3e07e769ee9607fae57b616e38
MagicalRecord: 53bed74b4323b930992a725be713e53b37d19755
MJExtension: 635f2c663dcb1bf76fa4b715b2570a5710aec545
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
...
...
GMRouter/Classes/GMRouter+gm.h
View file @
c3a5da24
...
...
@@ -8,10 +8,15 @@
#import "GMRouter.h"
#import "UIResponder+router.h"
NS_ASSUME_NONNULL_BEGIN
//NS_ASSUME_NONNULL_BEGIN
extern
NSString
*
const
GMRouterProtocolPrefix
;
@interface
GMRouter
(
gm
)
/**
* 初始化Map
*
*/
-
(
void
)
initializeRouteMap
;
/**
* 添加的模块例如: Target_common
...
...
@@ -30,10 +35,10 @@ extern NSString *const GMRouterProtocolPrefix;
* 通过协议 跳转到对应的vc
* @param urlScheme 协议名字
* 例如gengmei://welfare_special?service_id=5930&is_new_special=0
* @param
router
Block 需要回调的block
* @param
complete
Block 需要回调的block
* @return vc的实例
*/
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
completeBlock
:(
GMRouter
Block
)
router
Block
;
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
completeBlock
:(
GMRouter
CompleteBlock
)
complete
Block
;
/**
* 通过协议 跳转到对应的vc
...
...
@@ -41,15 +46,10 @@ extern NSString *const GMRouterProtocolPrefix;
* 例如gengmei://welfare_special
* @param params 创建vc初始化要传递的参数
* {@"service_id": @"5930",@"is_new_special": @0}
* @param completeBlock 需要回调的block
* @return vc的实例
*/
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
params
:(
NSDictionary
*
)
params
routerBlock
:(
GMRouterBlock
)
routerBlock
;
/**
* 初始化Map
*
*/
-
(
void
)
initializeRouteMap
;
-
(
id
)
pushScheme
:(
NSString
*
)
urlScheme
params
:(
NSDictionary
*
)
params
completeBlock
:(
GMRouterCompleteBlock
)
completeBlock
;
@end
NS_ASSUME_NONNULL_END
//
NS_ASSUME_NONNULL_END
GMRouter/Classes/GMRouter+gm.m
View file @
c3a5da24
...
...
@@ -15,9 +15,6 @@
#pragma clang diagnostic ignored "-Wundeclared-selector"
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
NSString
*
const
GMRouterActionPrefix
=
@"Action_"
;
NSString
*
const
GMRouterActionSuffix
=
@":"
;
NSString
*
const
GMRouterTargetPrefix
=
@"Target_"
;
NSString
*
const
GMRouterProtocolPrefix
=
@"gengmei://"
;
/**
增加一个模块, 需要在路由做映射,
...
...
@@ -37,22 +34,21 @@ static NSMutableDictionary *routeMap = nil;
self
.
targets
=
[
NSMutableArray
arrayWithObjects
:
GMRouterTargetAI
,
GMRouterTargetBanking
,
GMRouterTargetCommunity
,
GMRouterTargetWeb
,
nil
];
}
#pragma mark - 跳转协议方法
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
{
return
[
self
pushScheme
:
urlScheme
completeBlock
:
NULL
];
}
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
completeBlock
:
(
GMRouterBlock
)
routerBlock
{
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
completeBlock
:
(
GMRouterCompleteBlock
)
completeBlock
{
return
[
self
pushScheme
:
urlScheme
params
:@{}
completeBlock
:
completeBlock
];
}
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
params
:
(
NSDictionary
*
)
params
completeBlock
:
(
GMRouterCompleteBlock
)
completeBlock
{
if
(
!
[
urlScheme
hasPrefix
:
GMRouterProtocolPrefix
])
{
urlScheme
=
[
NSString
stringWithFormat
:
@"%@%@"
,
GMRouterProtocolPrefix
,
urlScheme
];
}
if
(
!
urlScheme
.
length
)
{
return
nil
;
}
NSString
*
encodeUrlScheme
=
[
self
URLEncodeString
:
urlScheme
];
NSDictionary
*
params
=
[
self
getParams
:
encodeUrlScheme
];
return
[
self
pushScheme
:
encodeUrlScheme
params
:
params
completeBlock
:
routerBlock
];
}
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
params
:
(
NSDictionary
*
)
params
completeBlock
:
(
GMRouterBlock
)
routerBlock
{
NSMutableDictionary
*
allParams
=
[
NSMutableDictionary
dictionaryWithDictionary
:
params
];
NSString
*
encodeUrlScheme
=
[
self
URLEncodeString
:
urlScheme
];
NSString
*
host
=
[
self
getHost
:
urlScheme
];
...
...
@@ -65,16 +61,16 @@ static NSMutableDictionary *routeMap = nil;
//如果是push 过来的 或者需要回调的在此赋值
if
([
vc
isKindOfClass
:[
UIViewController
class
]])
{
UIViewController
*
VC
=
(
UIViewController
*
)
vc
;
[
self
vcAutoIsPushWith
:
vc
params
:
params
];
}
// 赋值回调过程
if
([
vc
isKindOfClass
:[
UIResponder
class
]])
{
UIResponder
*
VC
=
(
UIResponder
*
)
vc
;
__weak
typeof
(
self
)
weakSelf
=
self
;
VC
.
routerBlock
=
^
(
NSDictionary
*
_Nonnull
params
)
{
routerBlock
(
params
);
UIResponder
*
respondeer
=
(
UIResponder
*
)
vc
;
respondeer
.
routerCompleteBlock
=
^
(
NSDictionary
*
_Nonnull
params
)
{
if
(
completeBlock
)
{
completeBlock
(
params
);
}
};
}
return
vc
;
...
...
GMRouter/Classes/UIResponder+router.h
View file @
c3a5da24
...
...
@@ -8,10 +8,10 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef
void
(
^
GMRouterBlock
)(
NSDictionary
*
params
);
@interface
UIResponder
(
router
)
@property
(
nonatomic
,
copy
)
GMRouterBlock
routerBlock
;
typedef
void
(
^
GMRouterCompleteBlock
)(
NSDictionary
*
params
);
@interface
UIResponder
(
router
)
@property
(
nonatomic
,
copy
)
GMRouterCompleteBlock
routerCompleteBlock
;
@end
NS_ASSUME_NONNULL_END
GMRouter/Classes/UIResponder+router.m
View file @
c3a5da24
...
...
@@ -9,12 +9,11 @@
#import <objc/runtime.h>
@implementation
UIResponder
(
router
)
-
(
GMRouter
Block
)
router
Block
{
return
objc_getAssociatedObject
(
self
,
@selector
(
routerBlock
));
-
(
GMRouter
CompleteBlock
)
routerComplete
Block
{
return
objc_getAssociatedObject
(
self
,
@selector
(
router
Complete
Block
));
}
-
(
void
)
setRouter
Block
:
(
GMRouterBlock
)
router
Block
{
objc_setAssociatedObject
(
self
,
@selector
(
router
Block
),
router
Block
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
-
(
void
)
setRouter
CompleteBlock
:
(
GMRouterCompleteBlock
)
routerComplete
Block
{
objc_setAssociatedObject
(
self
,
@selector
(
router
CompleteBlock
),
routerComplete
Block
,
OBJC_ASSOCIATION_COPY_NONATOMIC
);
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment