- 在Info-URL Types 配置
URL - Schemes — test
然后跟h5约定 他们回传使用 test:// 开头的一串字符串
- 在AppDelegate中
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options { }
把带参数URL解析成字典, 传给对应的VC
NSArray *hostArr = [url.absoluteString componentsSeparatedByString:@"?"];
if (hostArr.count <= 1) {
return;
}
NSArray *kvArr = [hostArr.lastObject componentsSeparatedByString:@"&"];
NSMutableDictionary *newDic = [NSMutableDictionary new];
for (NSString *kv in kvArr) {
NSArray *arr = [kv componentsSeparatedByString:@"="];
NSString *value = arr[1];
[newDic setObject:[value stringByRemovingPercentEncoding] forKey:[arr firstObject]];
}