Add callback requests and callback handlers #422
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
PaywallPresentationHandlerNote: need to test, my simulators are not working again
Checklist
CHANGELOG.mdfor any breaking changes, enhancements, or bug fixes.swiftlintin the main directory and fixed any issues.Greptile Overview
Greptile Summary
Adds custom callback support to the iOS SDK, enabling paywalls to invoke developer-defined async handlers for custom validation and business logic. The implementation follows the existing permission handling pattern with a thread-safe registry that maps paywall identifiers to callback handlers.
CustomCallback,CustomCallbackResult,CustomCallbackBehavior) for callback requests and responsesCustomCallbackRegistryfor thread-safe handler storage usingNSLockPaywallPresentationHandlerwithonCustomCallback()method for registering handlersPaywallMessageHandlerwith proper error handlingIssues:
Confidence Score: 4/5
Important Files Changed
Sequence Diagram
sequenceDiagram participant App as iOS App participant Handler as PaywallPresentationHandler participant Registry as CustomCallbackRegistry participant Superwall as Superwall SDK participant WebView as Paywall WebView participant MessageHandler as PaywallMessageHandler App->>Handler: onCustomCallback(handler) Note over Handler: Stores handler reference App->>Superwall: register(placement, handler: Handler) Superwall->>WebView: Present Paywall WebView-->>Superwall: onPresented(paywallInfo) Superwall->>Registry: register(paywallIdentifier, handler) Note over Registry: Maps identifier -> handler WebView->>MessageHandler: requestCallback(name, behavior, variables) MessageHandler->>Registry: getHandler(paywallIdentifier) Registry-->>MessageHandler: Return handler closure alt Handler exists MessageHandler->>Handler: await handler(CustomCallback) Handler-->>App: Execute callback logic App-->>Handler: Return CustomCallbackResult Handler-->>MessageHandler: Result (success/failure + data) MessageHandler->>WebView: sendCallbackResult(status, data) else No handler MessageHandler->>WebView: sendCallbackResult(failure) end WebView-->>Superwall: onDismissed(paywallInfo) Superwall->>Registry: unregister(paywallIdentifier) Note over Registry: Remove handler mappingContext used:
dashboard- CLAUDE.md (source)