feat(ios): implement configureNativeFetcher and setActiveDidFromHost methods

Implemented TimeSafari integration configuration methods:

configureNativeFetcher():
- Accepts apiBaseUrl, activeDid, and jwtToken/jwtSecret
- Stores configuration as JSON in UserDefaults
- Matches Android database storage pattern
- Supports backward compatibility (jwtToken/jwtSecret)
- Stores configuredAt timestamp

setActiveDidFromHost():
- Simpler method for updating just the activeDid
- Updates activeDid in UserDefaults
- Updates existing native fetcher config if present
- Stores updatedAt timestamp

iOS Adaptations:
- Uses UserDefaults instead of database (iOS equivalent of SharedPreferences)
- JSON serialization for config storage
- No native fetcher interface (unlike Android) - config stored for background tasks

Progress: 19/52 methods implemented (37% complete)
This commit is contained in:
Matthew Raymer
2025-11-11 02:07:59 -08:00
parent 17ede3ab20
commit ebab224916

View File

@@ -735,6 +735,110 @@ public class DailyNotificationPlugin: CAPPlugin {
}
}
/**
* Configure native fetcher
*
* Configures the native content fetcher with API credentials.
* Stores configuration in UserDefaults for persistence.
*
* Note: iOS doesn't have the same native fetcher interface as Android.
* Configuration is stored and can be used by background fetch tasks.
*
* Equivalent to Android's configureNativeFetcher method.
*/
@objc func configureNativeFetcher(_ call: CAPPluginCall) {
guard let options = call.options else {
call.reject("Options are required")
return
}
// Extract required parameters
guard let apiBaseUrl = options["apiBaseUrl"] as? String else {
call.reject("apiBaseUrl is required")
return
}
guard let activeDid = options["activeDid"] as? String else {
call.reject("activeDid is required")
return
}
// Support both jwtToken and jwtSecret for backward compatibility
guard let jwtToken = (options["jwtToken"] as? String) ?? (options["jwtSecret"] as? String) else {
call.reject("jwtToken or jwtSecret is required")
return
}
print("DNP-PLUGIN: Configuring native fetcher: apiBaseUrl=\(apiBaseUrl), activeDid=\(activeDid.prefix(30))...")
// Store configuration in UserDefaults (matching Android database storage)
let configId = "native_fetcher_config"
let configKey = "DailyNotificationNativeFetcherConfig"
let config: [String: Any] = [
"apiBaseUrl": apiBaseUrl,
"activeDid": activeDid,
"jwtToken": jwtToken,
"configuredAt": Date().timeIntervalSince1970 * 1000
]
// Store as JSON string for consistency with Android
do {
let jsonData = try JSONSerialization.data(withJSONObject: config, options: [])
let jsonString = String(data: jsonData, encoding: .utf8) ?? "{}"
UserDefaults.standard.set(jsonString, forKey: configKey)
UserDefaults.standard.synchronize()
print("DNP-PLUGIN: Native fetcher configuration stored successfully")
call.resolve()
} catch {
print("DNP-PLUGIN: Failed to store native fetcher config: \(error)")
call.reject("Failed to store configuration: \(error.localizedDescription)")
}
}
/**
* Set active DID from host
*
* Sets the active DID (identity) for TimeSafari integration.
* This is a simpler method than configureNativeFetcher for just updating the DID.
*
* Equivalent to Android's setActiveDidFromHost method.
*/
@objc func setActiveDidFromHost(_ call: CAPPluginCall) {
guard let activeDid = call.getString("activeDid") else {
call.reject("activeDid is required")
return
}
print("DNP-PLUGIN: Setting activeDid from host: \(activeDid.prefix(30))...")
// Store activeDid in UserDefaults
let keyActiveDid = "DailyNotificationActiveDid"
UserDefaults.standard.set(activeDid, forKey: keyActiveDid)
UserDefaults.standard.synchronize()
// If there's existing native fetcher config, update it
let configKey = "DailyNotificationNativeFetcherConfig"
if let configJson = UserDefaults.standard.string(forKey: configKey),
let configData = configJson.data(using: .utf8),
var config = try? JSONSerialization.jsonObject(with: configData) as? [String: Any] {
config["activeDid"] = activeDid
config["updatedAt"] = Date().timeIntervalSince1970 * 1000
if let updatedJsonData = try? JSONSerialization.data(withJSONObject: config, options: []),
let updatedJsonString = String(data: updatedJsonData, encoding: .utf8) {
UserDefaults.standard.set(updatedJsonString, forKey: configKey)
UserDefaults.standard.synchronize()
}
}
print("DNP-PLUGIN: ActiveDid set successfully")
call.resolve()
}
// MARK: - Private Implementation Methods
private func setupBackgroundTasks() {