Skip to main content

(Optional) Widget Events

How to Enable Events?

Please note, events are "disabled" by default. Thus, a developer who wishes to receive widget events should call enableEvents() method on SFWidget before calling the configure method, see example below:

self.sfWidget = SFWidget(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 0))
self.sfWidget.enableEvents()
self.sfWidget.configure(with: self, url: OBConf.baseURL, widgetId: self.widgetId, installationKey: OBConf.installationKey)

How to "Catch" events?

Please make sure to implement the optional SFWidgetDelegate method:

- (void) widgetEvent:(NSString * _Nonnull)eventName additionalData:(NSDictionary<NSString *, id>  * _Nonnull)additionalData;

For example:

func widgetEvent(_ eventName: String, additionalData: [String : Any]) {
print("App revceived widgetEvent: \(eventName) with data: \(additionalData)")
}

How to test all event types? (during development)

Just use testModeAllEvents() instead of enableEvents(), see example below:

self.sfWidget = SFWidget(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 0))
self.sfWidget.testModeAllEvents()
self.sfWidget.configure(with: self, url: OBConf.baseURL, widgetId: self.widgetId, installationKey: OBConf.installationKey)

This will cause the SDK to dispatch an example event for every possible type of event.

Event Types

Here is the list of event types:

  • ready
  • rendered
  • dataReturned
  • viewability