Files
divkit/client/ios/Sample/DivKitSample/SampleDivActionHandler.swift
T
morevsavva 48d10ebe89 Sample DivView integration.
4c91b25d4e29986cab6643ac5cdabcfb8ede1399
2024-07-25 14:08:21 +03:00

38 lines
1016 B
Swift

import DivKit
import Foundation
import UIKit
final class SampleDivActionHandler: DivUrlHandler {
weak var hostViewController: UIViewController?
init(hostViewController: UIViewController) {
self.hostViewController = hostViewController
}
func handle(_ url: URL, info _: DivActionInfo, sender _: AnyObject?) {
guard let components = url.components, components.scheme == scheme else {
return
}
switch components.host {
case "toast":
if let text = components.queryItems?.first?.name, let hostViewController {
showAlert(on: hostViewController, message: text)
}
default:
return
}
}
}
private let scheme = "sample-action"
private func showAlert(
on viewController: UIViewController,
message: String
) {
let alert = UIAlertController(title: "Sample alert", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
viewController.present(alert, animated: true, completion: nil)
}