Events
let registration = OneSygnal.shared.on("survey:shown") { data in
let surveyId = data as? String
print(surveyId ?? "")
}
// unsubscribe:
registration.cancel()on() returns a Registration; call .cancel() to stop receiving that event. Double-cancel
is a no-op. There is no off(event, callback) on iOS — Registration is the only
unsubscribe mechanism (Swift closures aren’t Equatable, so there’s nothing to match by
reference the way web’s off() does).
Event names and payloads
| Event | Payload (data as? …) | Notes |
|---|---|---|
ready | nil | Fires once initialize() has fully settled successfully — the same moment its completion resolves true. A listener registered after ready already fired still receives it immediately (a replay latch on readyEmitted). |
survey:shown | String — the survey ID | Fires once the survey overlay’s UIWindow is confirmed attached. Not an object — cast with data as? String, not data as? [String: Any]. |
survey:completed | String — the survey ID | Fires once a survey is fully completed. |
survey:dismissed | String — the survey ID | Fires when a survey is dismissed without completion — including the fail-closed path for an unsupported question type. |
survey:question_answered | [String: Any] with surveyId: String, questionId: String | Fires once per answered question. This is iOS/Android’s name; web’s equivalent is survey:step, with a different payload shape (adds a step index) — there is no survey:step on iOS. |
survey:shown/survey:completed/survey:dismissed payloads are a bare String, not
an object — verified directly against emit("survey:shown", survey.id) etc. in
Api/OneSygnal.swift. Web’s equivalent payloads are objects ({ surveyId }). Don’t assume
the shape is the same across platforms if you’re sharing analytics-forwarding code between
web and native.
What’s absent on iOS
There is no survey:step on iOS — that’s web’s name for what iOS calls
survey:question_answered, with a wider payload (step index included). One name/payload
should probably win eventually, but renaming either breaks existing integrators of that
platform, so both are documented as-is. See Platform Parity.