Walnut Callback Test

URL Scheme Callback Testing

👆 Tap any button to trigger a callback to the app

Basic Callbacks
Simple Callback Success with Message Error Callback
OAuth Simulation
OAuth Token Callback Authorization Code
walnut://auth?token=...&user_id=...
Payment Simulation
Payment Success Payment Cancelled
Custom Callback
walnut://callback?key=value
📚 Implementation Guide
URL Scheme Format â–¼
Basic Structure
scheme://host/path?key=value
Examples
// Simple callback walnut://callback // With parameters walnut://callback?status=success&id=123 // OAuth style walnut://auth?code=abc123&state=xyz // Deep link with path walnut://app/profile/settings?tab=security
💡 Use encodeURIComponent() for special characters in values
HTML Link Implementation â–¼
Anchor Tag
<!-- Simple link --> <a href="walnut://callback"> Open App </a> <!-- With parameters --> <a href="walnut://callback?action=login&user=123"> Login Callback </a>
JavaScript Implementation â–¼
Basic Navigation
// Direct navigation window.location.href = 'walnut://callback?status=done'; // With dynamic parameters const params = new URLSearchParams({ action: 'complete', orderId: 'ORD-001' }); window.location.href = `walnut://payment?${params}`;
Reusable Function
function sendCallback(host, params = {}) { const query = new URLSearchParams(params); const url = query.toString() ? `walnut://${host}?${query}` : `walnut://${host}`; window.location.href = url; } // Usage sendCallback('auth', { token: 'abc123' });
iOS Swift Handler â–¼
Info.plist Configuration
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>yourapp</string> </array> </dict> </array>
SwiftUI Handler
@main struct YourApp: App { var body: some Scene { WindowGroup { ContentView() .onOpenURL { url in handleCallback(url) } } } func handleCallback(_ url: URL) { guard url.scheme == "yourapp" else { return } let host = url.host ?? "" let params = URLComponents( url: url, resolvingAgainstBaseURL: false )?.queryItems?.reduce( into: [String: String]() ) { dict, item in dict[item.name] = item.value } ?? [:] // Handle by host switch host { case "auth": handleAuth(params) case "payment": handlePayment(params) default: break } } }
Common Parameter Patterns â–¼
OAuth / Authentication
// Authorization Code Flow yourapp://auth?code=AUTH_CODE&state=STATE // Token Response yourapp://auth?access_token=TOKEN&expires_in=3600 // Error yourapp://auth?error=access_denied
Payment / Transaction
// Success yourapp://payment?status=completed&order_id=ORD-001 // Cancelled yourapp://payment?status=cancelled&reason=user_cancelled
Deep Link / Navigation
// Content yourapp://share?type=article&id=12345 // Settings yourapp://settings/notifications?enabled=true