Overview
Push notifications require linking each user to a unique identifier (app_user_id) that persists across sessions and devices. This identifier connects OneSignal, RevenueCat, and your backend database.
The same app_user_id must be used consistently across all services to ensure users receive the correct notifications.
Identity Resolution
On every app launch, resolve the user’s identity using the following priority:| Priority | Source | Description |
|---|---|---|
| 1 | Storage Vault | Synced via iCloud/Google backup |
| 2 | Restore Purchases | Recovers paying users via externalUserId |
| 3 | Install ID | Fallback for new users (despia.uuid) |
Implementation
App Startup
Execute this logic on every app launch:setonesignalplayerid:// protocol must be called on every app launch, not only during first install. Users who were active before push notifications were implemented will not trigger login flows again. This is the only opportunity to sync their identity to OneSignal.
User Login
When a user authenticates, the backend determines whether to claim the current identity or recover an existing one.User Logout
On logout, generate a new anonymous identifier. Do not reuse the device’sinstall_id to prevent identity collision between users on shared devices.
Push Permission
Automatic Mode (Default)
When Manual Push Permission is disabled in Despia settings, the permission prompt displays automatically on first launch. No additional code is required.Manual Mode
Enable Manual Push Permission in Despia settings to control when the prompt appears:Backend Implementation
Send Push Notification
Single User
Multiple Users
All Users
User Registration Endpoint
User Login Endpoint
Use row-level locking to prevent race conditions when multiple devices authenticate simultaneously.User-to-User Messaging
For direct messaging features, push notifications serve as a fallback when the recipient is not actively using the app. For real-time messaging, consider dedicated services such as Stream or XMPP.Database Schema
Offline Retry Queue
Process queued identity syncs on app launch:Protocol Reference
| Protocol | Purpose | When to Call |
|---|---|---|
setonesignalplayerid://?user_id=X | Set OneSignal external_user_id | Every app launch, login, logout |
readvault://?key=app_user_id | Read from Storage Vault | App startup |
setvault://?key=X&value=Y&locked=Z | Write to Storage Vault | After identity resolution |
getpurchasehistory:// | Get purchase history | Identity recovery |
registerpush:// | Request push permission | Manual mode only |
checkNativePushPermissions:// | Check push permission status | Settings screens |
settingsapp:// | Open system settings | Re-engage denied users |