NSURL *webUrl = [urls firstObject];HLog(@"[UI] scheme:%@", [webUrl scheme]); //协议HLog(@"[UI] host:%@", [webUrl host]); //域名HLog(@"[UI] absoluteString:%@", [webUrl absoluteString]); //完整的url字符串HLog(@"[UI] relativePath: %@", [webUrl relativePath]); //相对路径 searchHLog(@"[UI] port :%@", [webUrl port]); // 端口HLog(@"[UI] path: %@", [webUrl path]); // 路径HLog(@"[UI] pathComponents:%@", [webUrl pathComponents]); //searchHLog(@"[UI] Query:%@", [webUrl query]); //参数NSMutableDictionary *dic = [self getURLParameters:[webUrl absoluteString]];- (NSMutableDictionary *)getURLParameters:(NSString *)str {// 查找参数NSRange range = [str rangeOfString:@"?"];if (range.location == NSNotFound) {return nil;}NSMutableDictionary *params = [NSMutableDictionary dictionary];// 截取参数NSString *parametersString = [str substringFromIndex:range.location + 1];// 判断参数是单个参数还是多个参数if ([parametersString containsString:@"&"]) {// 多个参数,分割参数NSArray *urlComponents = [parametersString componentsSeparatedByString:@"&"];for (NSString *keyValuePair in urlComponents) {// 生成Key/ValueNSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];// Key不能为nilif (key == nil || value == nil) {continue;}id existValue = [params valueForKey:key];if (existValue != nil) {// 已存在的值,生成数组if ([existValue isKindOfClass:[NSArray class]]) {// 已存在的值生成数组NSMutableArray *items = [NSMutableArray arrayWithArray:existValue];[items addObject:value];[params setValue:items forKey:key];} else {// 非数组[params setValue:@[existValue, value] forKey:key];}} else {// 设置值[params setValue:value forKey:key];}}} else {// 单个参数// 生成Key/ValueNSArray *pairComponents = [parametersString componentsSeparatedByString:@"="];// 只有一个参数,没有值if (pairComponents.count == 1) {return nil;}// 分割值NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];// Key不能为nilif (key == nil || value == nil) {return nil;}// 设置值[params setValue:value forKey:key];}return params;
}