Skip to Content
PlatformsiOSAPI Reference

API Reference

Source: apps/ios-sdk/Sources/OneSygnal/Api/OneSygnal.swift, singleton OneSygnal.shared.

Most methods that do meaningful async work ship as two overloads of the same name: a completion-handler version and an async version (withCheckedContinuation wrapping the former). Swift’s overload resolution picks the right one per call site — a call with a trailing closure resolves to the completion-based version; an awaited call or one with no completion argument resolves to the async version. Kotlin can’t do this (a suspend fun can’t overload past a defaulted parameter), which is why Android uses …Await suffixes instead — a language constraint, not an inconsistency between the two SDKs.

Configuration

MethodSignatureNotes
setApiKey(_ apiKey: String) -> VoidOverrides the Info.plist key. Must be called before initialize(). Blank string is a silent no-op.
setLocale(_ locale: String) -> VoidLive-reactive after initialize() — re-fetches config/surveys under the new locale.

Lifecycle

MethodSignatureNotes
initialize(completion: ((Bool) -> Void)? = nil) -> VoidCompletion fires once config is fetched, user is ensured, surveys are fetched, and the rules engine is loaded — true on success. Already-initialized calls resolve true immediately. Resolves false if the API key can’t be resolved (see Troubleshooting).
initialize() async -> BoolAsync overload of the above.
isInitialized() -> BoolReads back whether initialize has completed.
shutdown(completion: (() -> Void)? = nil) -> VoidFlushes pending events, tears down timers/listeners, marks uninitialized. No-op (completion still fires) if not initialized.
shutdown() async -> VoidAsync overload of the above.

Identity

MethodSignatureNotes
identify(_ userId: String, attributes: [String: Any]? = nil, completion: ((Bool) -> Void)? = nil) -> VoidNo-op (completion resolves false) if not initialized. Re-fetches surveys if more than 60s have elapsed since the last fetch.
identify(_ userId: String, attributes: [String: Any]? = nil) async -> BoolAsync overload of the above.
logout(completion: (() -> Void)? = nil) -> VoidClears the identified user, reverting to anonymous tracking. Re-fetches surveys. No-op if not initialized.
logout() async -> VoidAsync overload of the above.
reset(completion: (() -> Void)? = nil) -> VoidMints a new anonymous ID and re-fetches surveys — distinct from logout(). No-op if not initialized.
reset() async -> VoidAsync overload of the above.

Tracking and surveys

MethodSignatureNotes
track@discardableResult (_ eventName: String, properties: [String: Any?] = [:]) -> BoolReturns false if not initialized or surveys are disabled; otherwise delegates to EventTracker.track and returns its result.
setSurveysEnabled(_ enabled: Bool) -> VoidGlobally suppresses/re-enables survey overlays without affecting event tracking.
areSurveysEnabled() -> BoolReads back the flag set by setSurveysEnabled. Defaults true.

Events

MethodSignatureNotes
on@discardableResult (_ event: String, callback: @escaping (Any?) -> Void) -> RegistrationSee Events for names and payloads. "ready" replays immediately to a listener registered after it already fired.
Registration.cancel() -> VoidStops that specific registration. Double-cancel is a no-op. There is no free-standing off(event, callback)Registration is the only unsubscribe mechanism, because Swift closures aren’t Equatable (so there’s nothing to match by reference the way web’s off() does).

flush is absent

Web exposes a flush() that forces pending events/responses to send immediately. iOS does not: EventTracker and ResponseFlusher’s periodic timers (event flush, response flush) are internal, with nothing exposed for a caller to trigger early. Same on Android.

Not part of the supported surface

  • setSdkWrapper(library:version:) — public, but exists only for wrapper SDKs (the Flutter plugin calls it at registration to override $lib/$lib_version device-context fields). Not intended for direct use by native app integrators.
  • emit(_:_:)internal visibility, widened only so the same-module test target can drive it directly. Not part of the public surface.

See Platform Parity for what exists on every platform.