Setting Callbacks
Every feature reports events to one shared receiver: a delegate on iOS or a listener on Android. Each feature page lists its events: Checkout Card, In-Game Browser, and QR Code Linking.
Set the receiver
Set the receiver on the main thread before you open anything. Open calls work from any thread.
StashNative.sharedInstance().delegate = self
StashNative.getInstance().setListener(listener);
- iOS: all
StashNativeDelegatemethods are optional. The SDK does not retain the delegate; keep your own reference. - Android: extend
StashNative.StashNativeListenerAdapterand override only what you need. The SDK keeps the listener until you callsetListener(null).
How shared callbacks work
StashNativeruns one card or scanner at a time, so one receiver serves every feature. On Android,openBrowsercan also open a browser over an open card or scanner; it reportsonBrowserDismissedseparately. Each event has its own method, which tells you the feature that sent it.- The receiver is global, not tied to an open call. Each event goes to the receiver set when it fires, including events from a presentation that is already open. Use a long-lived object, such as your store or app controller, not a screen that can close or be recreated during checkout.
- Events arrive on the main thread, so you can update the UI directly.
- Clearing the receiver stops future events. Events are never replayed.
- Engine wrappers register one receiver and forward its events to the engine; see Engine Wrappers.
Order of events
Each presentation ends with one final event, listed on its feature page. Resume the game when it arrives. You can open the next card, browser, or scanner from that callback. Two calls end a presentation without events: resetPresentationState() closes the card or scanner, and Safari on iOS; dismissSafariViewController() closes Safari on iOS when your app handles the payment deep link itself.