-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HELP] listen to events in swiftUI #171
Comments
@EduarRugamas to be on the same page, you can prevent hcaptcha request again on expiration by passing You mentioned Maybe you can explain your scenario, do you need to renew the token on expiration? |
Hello, I attach a method where to declare the Hcaptcha onEvent The behavior I'm trying to get is the following: When I check for the first time if the event is triggered in the onEvent and if the corresponding print() is displayed in the console |
It isn't clear when you call import SwiftUI
import HCaptcha
// Wrapper-view to provide UIView instance
struct UIViewWrapperView: UIViewRepresentable {
var uiView = UIView()
func makeUIView(context: Context) -> UIView {
uiView.backgroundColor = .gray
return uiView
}
func updateUIView(_ view: UIView, context: Context) {
// nothing to update
}
}
class HCaptchaViewModel: ObservableObject {
let hcaptcha: HCaptcha!
init() {
self.hcaptcha = try! HCaptcha()
}
func configure(_ hostView: UIViewWrapperView) {
hcaptcha.configureWebView { webview in
webview.frame = hostView.uiView.bounds
}
hcaptcha.onEvent { (event, data) in
print("HCaptcha onEvent \(event.rawValue)")
}
}
func validate(_ hostView: UIViewWrapperView) {
hcaptcha.validate(on: hostView.uiView) { result in
print("HCaptcha result \(try? result.dematerialize())")
}
}
}
struct HCaptchaView: View {
@StateObject var model = HCaptchaViewModel()
let placeholder = UIViewWrapperView()
var body: some View {
VStack{
placeholder.frame(width: 640, height: 640, alignment: .center)
Button(
"validate",
action: { model.validate(placeholder) }
).padding()
}
.onAppear {
model.configure(placeholder)
}
}
} |
Thank you so much |
Hello development team
I have a question regarding listening to Hcaptcha events in SwiftUI
since your example does not show how to listen
according to your documentation in the UIKIT example
It is defined in the method where the webview is configured
but it gives me the following problem
When you start the app and load the Hcaptcha for the first time, it apparently shows the event heard
but then when you take on the challenge and be successful
After it expires and I do the challenge again, the events heard are no longer displayed on the console.
Is there any solution to this problem
Thanks for your help in advance
I attach implementation in SwiftUI according to the documentation provided
The text was updated successfully, but these errors were encountered: