-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMRDeepLinkParser.swift
More file actions
36 lines (29 loc) · 896 Bytes
/
MRDeepLinkParser.swift
File metadata and controls
36 lines (29 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// File.swift
// ModuleRoute
//
// Created by GIKI on 2025/2/15.
//
import Foundation
public struct DeepLinkParser {
private var schemeHandlers: [String: (URL) -> MRRoute?] = [:]
public mutating func register(scheme: String, handler: @escaping (URL) -> MRRoute?) {
schemeHandlers[scheme] = handler
}
public func parse(url: URL) -> MRRoute? {
guard let scheme = url.scheme else { return nil }
return schemeHandlers[scheme]?(url)
}
}
extension MRRoute {
static func from(url: URL) -> MRRoute? {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return nil
}
var params: [String: Any] = [:]
components.queryItems?.forEach { item in
params[item.name] = item.value
}
return BasicRoute(params: params)
}
}