Commit 3c060557 authored by jz's avatar jz

update GMRouter

parent 8160d8d4
......@@ -36,7 +36,7 @@ static NSMutableDictionary *routeMap = nil;
- (void)initializeRouteMap {
routeMap = [[NSMutableDictionary alloc] initWithCapacity:50];
NSArray *arr = @[GMRouterTargetAI, GMRouterTargetBanking, GMRouterTargetCommunity, GMRouterTargetWeb];
NSArray *arr = @[GMRouterTargetAI, GMRouterTargetBanking, GMRouterTargetCommunity, GMRouterTargetWeb];
for (NSString *clsStr in arr) {
NSDictionary *dict = [self getMethods:clsStr];
[routeMap addEntriesFromDictionary:dict];
......@@ -73,7 +73,8 @@ static NSMutableDictionary *routeMap = nil;
// 获取方法的参数列表
int arguments = method_getNumberOfArguments(methods[i]);
NSAssert([dict.allKeys containsObject:name], @"Target_后不能为空!请注意Target");
NSString *promoteStr = [NSString stringWithFormat:@"%@-内有重复的方法名-%@", clsStr, name];
NSAssert(![dict.allKeys containsObject:name], promoteStr);
//因为消息发送的时候会有两个默认的参数(消息接受者和方法名),所以需要减去2
dict[name] = targetValue;
......@@ -125,14 +126,37 @@ static NSMutableDictionary *routeMap = nil;
}
- (id)pushScheme:(NSString *)urlScheme {
NSString *encodeUrlScheme = [self URLDecodedString:urlScheme];
NSString *encodeUrlScheme = [self URLEncodeString:urlScheme];
NSURL *url = [NSURL URLWithString:encodeUrlScheme];
if (!url) {
// debugLog(@"协议出错了!");
}
NSString *host = url.host;
NSString *targetName = [routeMap objectForKey:host];
NSDictionary *params = [self urlQueryToDictionary:encodeUrlScheme];
NSDictionary *params;
NSArray *array = [encodeUrlScheme componentsSeparatedByString:@"url="];
if (([host isEqualToString:@"third_webview"] || [host isEqualToString:@"common_webview"]) && array.count > 1) {
NSString *value = array[1];
while ([value rangeOfString:@"%"].length != 0) {
value = [self URLDecodedString:value];
}
params = @{@"url":value};
//拦截所有的即将调转的url(value),如果不在白名单之中,让其使用GMThirdWebViewController加载.
NSString *valueHost = [[NSURL URLWithString:value] host];
// if ([GMServerDomains allowURLHost:valueHost] == NO) {
//#if defined DEBUG
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"webView需添加白名单" message:value delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
// [alertView show];
//#endif
//
// host = @"third_webview";
// }
} else {
params = [self urlQueryToDictionary:encodeUrlScheme];
}
// NSDictionary *params = [self urlQueryToDictionary:encodeUrlScheme];
return [self performTarget:targetName action:host params:params shouldCacheTarget:NO];
}
......@@ -148,6 +172,8 @@ static NSMutableDictionary *routeMap = nil;
return [self performTarget:targetName action:host params:paramsDict shouldCacheTarget:NO];
}
#pragma mark - string to dict
- (NSDictionary*)urlQueryToDictionary:(NSString *)urlScheme {
NSURL* url1 = [NSURL URLWithString:urlScheme];
......@@ -197,6 +223,11 @@ static NSMutableDictionary *routeMap = nil;
}
- (NSString *)URLEncodeString:(NSString *)urlStr {
NSString *encodedString = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
return encodedString;
}
@end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment