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
8e52ca96
Commit
8e52ca96
authored
Dec 12, 2019
by
jz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify router
parent
2ee41ac2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
142 deletions
+61
-142
project.pbxproj
Example/Pods/Pods.xcodeproj/project.pbxproj
+0
-0
gm_router.plist
GMRouter/Assets/gm_router.plist
+0
-14
GMRouter+gm.m
GMRouter/Classes/GMRouter+gm.m
+61
-14
NSObject+gmKey.h
GMRouter/Classes/NSObject+gmKey.h
+0
-17
NSObject+gmKey.m
GMRouter/Classes/NSObject+gmKey.m
+0
-15
Target_commons.h
GMRouter/Classes/Target_commons.h
+0
-18
Target_commons.m
GMRouter/Classes/Target_commons.m
+0
-22
UIViewController+Router.h
GMRouter/Classes/UIViewController+Router.h
+0
-16
UIViewController+Router.m
GMRouter/Classes/UIViewController+Router.m
+0
-26
No files found.
Example/Pods/Pods.xcodeproj/project.pbxproj
View file @
8e52ca96
This diff is collapsed.
Click to expand it.
GMRouter/Assets/gm_router.plist
deleted
100644 → 0
View file @
2ee41ac2
<
?xml
v
e
rsion="
1
.
0
"
e
n
c
o
d
ing="UT
F
-
8
"?
>
<
!
D
O
C
TYP
E
plist
PU
B
LI
C
"-//
A
ppl
e C
omput
e
r//
D
T
D
PLIST
1
.
0
//
E
N"
"http://www.
a
ppl
e
.
c
om/
D
T
D
s/Prop
e
rtyList-
1
.
0
.
d
t
d
"
>
<
!--
gm_rout
e
r.plist
Po
d
s
C
r
ea
t
ed b
y
Q
14
on
2019
/
12
/
10
.
C
opyright
(
c
)
2019
___ORG
A
NIZ
A
TIONN
A
M
E
___.
A
ll
rights
r
e
s
e
rv
ed
.
--
>
<
plist
v
e
rsion="
1
.
0
"
>
<
d
i
c
t
>
<
/
d
i
c
t
>
<
/plist
>
GMRouter/Classes/GMRouter+gm.m
View file @
8e52ca96
...
...
@@ -7,6 +7,7 @@
#import "GMRouter+gm.h"
#import <objc/message.h>
#import <objc/runtime.h>
//nsstring
static
inline
BOOL
verifiedString
(
id
strlike
)
{
...
...
@@ -21,20 +22,69 @@ NSString *const GMRouterActionPrefix = @"Action_";
NSString
*
const
GMRouterActionSuffix
=
@":"
;
NSString
*
const
GMRouterTargetPrefix
=
@"Target_"
;
/**
增加一个魔块 需要在路由做映射
*/
NSString
*
const
GMRouterTargetAI
=
@"Target_AI"
;
NSString
*
const
GMRouterTargetBanking
=
@"Target_Banking"
;
NSString
*
const
GMRouterTargetCommunity
=
@"Target_Community"
;
NSString
*
const
GMRouterTargetWeb
=
@"Target_Web"
;
static
NSMutableDictionary
*
routeMap
=
nil
;
@implementation
GMRouter
(
gm
)
+
(
void
)
initialize
{
//私有库中只能这样写
NSBundle
*
bundle
=
[
NSBundle
bundleForClass
:[
GMRouter
class
]];
NSURL
*
bundleURL
=
[
bundle
URLForResource
:
@"QJRouter"
withExtension
:
@"bundle"
];
NSBundle
*
plistBundle
=
[
NSBundle
bundleWithURL
:
bundleURL
];
NSURL
*
plistUrl
=
[
plistBundle
URLForResource
:
@"gm_router"
withExtension
:
@"plist"
];
if
(
!
routeMap
)
{
routeMap
=
[[
NSMutableDictionary
alloc
]
initWithContentsOfURL
:
plistUrl
];
routeMap
=
[[
NSMutableDictionary
alloc
]
initWithCapacity
:
50
];
NSArray
*
arr
=
@[
GMRouterTargetAI
,
GMRouterTargetBanking
,
GMRouterTargetCommunity
,
GMRouterTargetWeb
];
for
(
NSString
*
clsStr
in
arr
)
{
NSDictionary
*
dict
=
[
self
getMethods
:
clsStr
];
[
routeMap
addEntriesFromDictionary
:
dict
];
}
}
}
#pragma mark - 获取类的所有方法
// 获取所有的方法
+
(
NSDictionary
*
)
getMethods
:
(
NSString
*
)
clsStr
{
Class
cls
=
NSClassFromString
(
clsStr
);
NSRange
range
=
[
clsStr
rangeOfString
:
@"Target_"
];
NSString
*
targetValue
=
[
clsStr
substringFromIndex
:
range
.
length
];
if
(
!
targetValue
.
length
)
{
return
@{};
}
NSObject
*
target
=
[[
cls
alloc
]
init
];
unsigned
int
count
=
0
;
NSMutableDictionary
*
dict
=
[
NSMutableDictionary
dictionary
];
// 获取类的所有 Method
Method
*
methods
=
class_copyMethodList
([
cls
class
],
&
count
);
for
(
NSUInteger
i
=
0
;
i
<
count
;
i
++
)
{
// 获取方法 Name
SEL
methodSEL
=
method_getName
(
methods
[
i
]);
const
char
*
methodName
=
sel_getName
(
methodSEL
);
NSString
*
name
=
[
NSString
stringWithUTF8String
:
methodName
];
//获取到的是这样的 pushToHospitalDetail: 因此要去掉:
NSString
*
rangeStr
=
@":"
;
if
([
name
containsString
:
rangeStr
])
{
NSRange
range
=
[
name
rangeOfString
:
rangeStr
];
name
=
[
name
substringToIndex
:
range
.
location
];
}
// 获取方法的参数列表
int
arguments
=
method_getNumberOfArguments
(
methods
[
i
]);
//因为消息发送的时候会有两个默认的参数(消息接受者和方法名),所以需要减去2
dict
[
name
]
=
targetValue
;
}
free
(
methods
);
return
dict
;
}
-
(
id
)
performAction
:
(
NSString
*
)
actionName
params
:
(
NSDictionary
*
)
params
shouldCacheTarget
:
(
BOOL
)
shouldCacheTarget
{
NSString
*
selName
=
@"createVC:"
;
...
...
@@ -81,12 +131,10 @@ static NSMutableDictionary *routeMap = nil;
// debugLog(@"协议出错了!");
}
NSString
*
host
=
url
.
host
;
NSDictionary
*
dict
=
[
routeMap
objectForKey
:
host
];
NSString
*
sel
=
dict
[
@"sel"
];
NSString
*
targetName
=
dict
[
@"target"
];
NSString
*
targetName
=
[
routeMap
objectForKey
:
host
];
NSDictionary
*
params
=
[
self
urlQueryToDictionary
:
encodeUrlScheme
];
return
[
self
performTarget
:
targetName
action
:
sel
params
:
params
shouldCacheTarget
:
NO
];
return
[
self
performTarget
:
targetName
action
:
host
params
:
params
shouldCacheTarget
:
NO
];
}
-
(
id
)
pushScheme
:
(
NSString
*
)
urlScheme
params
:
(
NSDictionary
*
)
params
{
...
...
@@ -95,10 +143,9 @@ static NSMutableDictionary *routeMap = nil;
if
(
!
url
)
{
}
NSString
*
host
=
url
.
host
;
NSDictionary
*
dict
=
[
routeMap
objectForKey
:
host
];
NSString
*
sel
=
dict
[
@"sel"
];
NSString
*
targetName
=
dict
[
@"target"
];
return
[
self
performTarget
:
targetName
action
:
sel
params
:
params
shouldCacheTarget
:
NO
];
NSString
*
targetName
=
[
routeMap
objectForKey
:
host
];
NSDictionary
*
paramsDict
=
[
self
urlQueryToDictionary
:
encodeUrlScheme
];
return
[
self
performTarget
:
targetName
action
:
host
params
:
paramsDict
shouldCacheTarget
:
NO
];
}
#pragma mark - string to dict
...
...
GMRouter/Classes/NSObject+gmKey.h
deleted
100644 → 0
View file @
2ee41ac2
//
// NSObject+gmKey.h
// MJExtension
//
// Created by Q14 on 2019/12/4.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface
NSObject
(
gmKey
)
@end
NS_ASSUME_NONNULL_END
GMRouter/Classes/NSObject+gmKey.m
deleted
100644 → 0
View file @
2ee41ac2
//
// NSObject+gmKey.m
// MJExtension
//
// Created by Q14 on 2019/12/4.
//
#import "NSObject+gmKey.h"
#import <MJExtension/MJExtension.h>
@implementation
NSObject
(
gmKey
)
+
(
id
)
mj_replacedKeyFromPropertyName121
:(
NSString
*
)
propertyName
{
return
[
propertyName
mj_underlineFromCamel
];
}
@end
GMRouter/Classes/Target_commons.h
deleted
100644 → 0
View file @
2ee41ac2
//
// Target_commons.h
// GMRouter
//
// Created by Q14 on 2019/11/28.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
extern
NSString
*
const
GMRouterTargetCommons
;
@interface
Target_commons
:
NSObject
// 自定义push方法
-
(
UIViewController
*
)
push_CommonViewController
:(
NSString
*
)
stringVCName
params
:(
NSDictionary
*
)
params
;
@end
NS_ASSUME_NONNULL_END
GMRouter/Classes/Target_commons.m
deleted
100644 → 0
View file @
2ee41ac2
//
// Target_commons.m
// GMRouter
//
// Created by Q14 on 2019/11/28.
//
#import "Target_commons.h"
NSString
*
const
GMRouterTargetCommons
=
@"commons"
;
@implementation
Target_commons
// 自定义push方法
-
(
UIViewController
*
)
push_CommonViewController
:(
NSString
*
)
stringVCName
params
:(
NSDictionary
*
)
params
{
// 因为action是从属于ModuleA的,所以action直接可以使用ModuleA里的所有声明
Class
class
=
NSClassFromString
(
stringVCName
);
UIViewController
*
controller
=
[[
class
alloc
]
init
];
return
controller
;
}
@end
GMRouter/Classes/UIViewController+Router.h
deleted
100644 → 0
View file @
2ee41ac2
//
// UIViewController+Router.h
// GMRouter
//
// Created by Q14 on 2019/11/28.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface
UIViewController
(
Router
)
-
(
id
)
createVC
:(
NSDictionary
*
)
dict
;
@end
NS_ASSUME_NONNULL_END
GMRouter/Classes/UIViewController+Router.m
deleted
100644 → 0
View file @
2ee41ac2
//
// UIViewController+Router.m
// GMRouter
//
// Created by Q14 on 2019/11/28.
//
#import "UIViewController+Router.h"
#import "GMRouter+gm.h"
#import <MJExtension/MJExtension.h>
@implementation
UIViewController
(
Router
)
-
(
id
)
createVC
:(
NSDictionary
*
)
dict
{
Class
class
=
getClassFromAtcion
(
_cmd
);
if
(
class
)
{
UIViewController
*
doc
=
self
;
doc
=
[[
class
alloc
]
init
];
doc
=
[
doc
mj_setKeyValues
:
dict
];
return
doc
;
}
return
nil
;
}
@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