Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2025-06-27 17:50:18 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6fa906d0462eb8d0ec9d26d507368bf6bd6997f4
6fa906d0
1 parent
59fd7b76
Proactive Database Initialization - Database ready from SDK startup
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
4 deletions
FRAMEWORK_MIGRATION_CHANGELOG.md
SwiftWarplyFramework/SwiftWarplyFramework/Core/WarplySDK.swift
FRAMEWORK_MIGRATION_CHANGELOG.md
View file @
6fa906d
...
...
@@ -1236,6 +1236,87 @@ public func requestRaw(_ endpoint: Endpoint) async throws -> [String: Any] {
**Result**
: ✅
**Universal fix for all context response parsing issues**
- getCampaigns and all other context endpoints now work correctly
---
#### **Issue #9: Database Initialization Timing (PROACTIVE FIX)**
**File**
:
`SwiftWarplyFramework/SwiftWarplyFramework/Core/WarplySDK.swift`
**Problem**
: Database was not initialized during SDK setup, causing authentication checks to fail
**Impact**
: ⚠️
**MEDIUM**
- Authentication logic bypassed, users don't get personalized experience
**Root Cause**
: Database initialization was happening lazily (on first access) rather than proactively during SDK initialization.
**Timing Issue**
:
1.
`WarplySDK.initialize()`
→ Device registration only
2.
`getCampaigns()`
→ Authentication check → ❌ Database not ready
3.
Database initializes lazily → ✅ Too late
**Solution**
:
**Proactive Database Initialization**
```
swift
public
func
initialize
(
callback
:
((
Bool
)
->
Void
)?
=
nil
)
{
// ... existing validation ...
// Initialize database and register device during initialization
Task
{
do
{
// 1. Initialize database FIRST to ensure it's ready for authentication checks
try
await
initializeDatabaseProactively
()
// 2. Then perform device registration
try
await
performDeviceRegistration
()
await
MainActor
.
run
{
print
(
"✅ [WarplySDK] SDK initialization completed successfully"
)
callback
?(
true
)
}
}
catch
{
// ... error handling ...
}
}
}
/// Initialize database proactively during SDK initialization
private
func
initializeDatabaseProactively
()
async
throws
{
print
(
"🗄️ [WarplySDK] Initializing database proactively during SDK setup..."
)
do
{
// Initialize the database with default configuration
try
await
DatabaseManager
.
shared
.
initializeDatabase
()
print
(
"✅ [WarplySDK] Database initialized successfully during SDK setup"
)
}
catch
{
print
(
"❌ [WarplySDK] Database initialization failed during SDK setup:
\(
error
)
"
)
throw
error
}
}
```
**Expected Results After Fix**
:
**SDK Initialization logs should show**
:
```
🏭 [WarplyConfiguration] Production configuration loaded
✅ [WarplySDK] Stored appUuid in UserDefaults: f83dfde1145e4c2da69793abb2f579af
🗄️ [WarplySDK] Initializing database proactively during SDK setup...
✅ [WarplySDK] Database initialized successfully during SDK setup
🔄 [WarplySDK] Performing automatic device registration...
[... registration ...]
✅ [WarplySDK] SDK initialization completed successfully
```
**getCampaigns logs should show**
:
```
🔍 [DatabaseManager] Retrieving TokenModel synchronously from database
✅ [DatabaseManager] Database ready - checking for tokens
ℹ️ [WarplySDK] User not authenticated - returning all basic campaigns without coupon filtering
```
**Key Benefits**
:
1.
**Proper Initialization Order**
- Database ready before any authentication checks
2.
**Better User Experience**
- Authenticated users get personalized campaigns + coupon filtering
3.
**Consistent Behavior**
- No more timing-dependent authentication failures
4.
**Future-Proof**
- All future authentication-dependent features will work correctly
**Result**
: ✅
**Database ready from SDK initialization**
- authentication logic works properly, users get appropriate campaign experience
---
### **🔧 Additional Safety Fixes - June 27, 2025 (Session 2)**
After the initial legacy credential removal, a comprehensive search revealed
**3 additional problematic checks**
that could still cause issues:
...
...
SwiftWarplyFramework/SwiftWarplyFramework/Core/WarplySDK.swift
View file @
6fa906d
...
...
@@ -390,9 +390,13 @@ public final class WarplySDK {
UserDefaults
.
standard
.
set
(
storage
.
appUuid
,
forKey
:
"appUuidUD"
)
print
(
"✅ [WarplySDK] Stored appUuid in UserDefaults:
\(
storage
.
appUuid
)
"
)
//
Automatically
register device during initialization
//
Initialize database and
register device during initialization
Task
{
do
{
// 1. Initialize database FIRST to ensure it's ready for authentication checks
try
await
initializeDatabaseProactively
()
// 2. Then perform device registration
try
await
performDeviceRegistration
()
await
MainActor
.
run
{
...
...
@@ -401,9 +405,9 @@ public final class WarplySDK {
}
}
catch
{
await
MainActor
.
run
{
print
(
"⚠️ [WarplySDK] SDK initialization completed with
registration
warning:
\(
error
.
localizedDescription
)
"
)
// Still consider initialization successful even if
registration fails
// The SDK can function with
out registration, but some features may be limited
print
(
"⚠️ [WarplySDK] SDK initialization completed with warning:
\(
error
.
localizedDescription
)
"
)
// Still consider initialization successful even if
some steps fail
// The SDK can function with
reduced functionality
callback
?(
true
)
}
}
...
...
@@ -435,6 +439,20 @@ public final class WarplySDK {
return
result
}
/// Initialize database proactively during SDK initialization
private
func
initializeDatabaseProactively
()
async
throws
{
print
(
"🗄️ [WarplySDK] Initializing database proactively during SDK setup..."
)
do
{
// Initialize the database with default configuration
try
await
DatabaseManager
.
shared
.
initializeDatabase
()
print
(
"✅ [WarplySDK] Database initialized successfully during SDK setup"
)
}
catch
{
print
(
"❌ [WarplySDK] Database initialization failed during SDK setup:
\(
error
)
"
)
throw
error
}
}
/// Perform device registration during initialization
private
func
performDeviceRegistration
()
async
throws
{
// Legacy credentials are deprecated - always proceed with registration if needed
...
...
Please
register
or
login
to post a comment