Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix: APNs push token sync and launch performance

libokaic5508c21af8e
diff --git a/Codync-iOS/App/AppDelegate.swift b/Codync-iOS/App/AppDelegate.swift
index c3c085bd..6800eff2 100644
--- a/Codync-iOS/App/AppDelegate.swift
+++ b/Codync-iOS/App/AppDelegate.swift
@@ -15,7 +15,6 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
- PremiumManager.shared.configure()
application.registerForRemoteNotifications()
NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: .main) { [weak self] _ in
Task { @MainActor in
@@ -26,6 +25,7 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
}
}
Task {
+ PremiumManager.shared.configure()
async let startReceiver: () = receiver.start()
async let loadPins: () = liveActivityManager.loadPinnedSessions()
async let loadPref: () = liveActivityManager.loadPreference()
diff --git a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 1.png b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 1.png
index 3d6cf3c6..c83049c6 100644
Binary files a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 1.png and b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 1.png differ
diff --git a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 2.png b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 2.png
index 3d6cf3c6..c83049c6 100644
Binary files a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 2.png and b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image 2.png differ
diff --git a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image.png b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image.png
index 3d6cf3c6..c83049c6 100644
Binary files a/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image.png and b/Codync-iOS/Assets.xcassets/CodyncIcon.imageset/image.png differ
diff --git a/Codync-iOS/Services/LiveActivityManager.swift b/Codync-iOS/Services/LiveActivityManager.swift
index ac7a5792..b0e145da 100644
--- a/Codync-iOS/Services/LiveActivityManager.swift
+++ b/Codync-iOS/Services/LiveActivityManager.swift
@@ -249,13 +249,24 @@ final class LiveActivityManager: ObservableObject {
lastOverallState = nil
}
- // Pro upgrade: if we have an activity without push token, recreate it
- if let activity = overallActivity, PremiumManager.shared.isPro, activity.pushToken == nil {
- logger.info("Pro active but Overall Activity has no push token — recreating")
- Task { await activity.end(nil, dismissalPolicy: .immediate) }
- overallActivity = nil
- lastOverallState = nil
- pushTokenTasks["__overall__"]?.cancel()
+ // Pro: ensure we're observing push token for existing activity
+ if let activity = overallActivity, PremiumManager.shared.isPro {
+ if activity.pushToken == nil && pushTokenTasks["__overall__"] == nil {
+ // Activity exists but wasn't created with pushType: .token — recreate
+ logger.info("Pro active but Overall Activity has no push token — recreating")
+ Task { await activity.end(nil, dismissalPolicy: .immediate) }
+ overallActivity = nil
+ lastOverallState = nil
+ } else if pushTokenTasks["__overall__"] == nil {
+ // Activity has token but we're not observing — start observing + save existing token
+ logger.info("Resuming push token observation for existing Overall Activity")
+ observeOverallPushToken(activity: activity)
+ if let token = activity.pushToken {
+ let hex = token.map { String(format: "%02x", $0) }.joined()
+ logger.info("Existing Overall push token: \(hex.prefix(8))...")
+ Task { await savePushToken(sessionId: "__overall__", tokenHex: hex) }
+ }
+ }
}
let active = sortedSessions(sessions.filter { $0.status != .completed })
@@ -476,11 +487,17 @@ final class LiveActivityManager: ObservableObject {
recordName: "pushtoken-\(sessionId)",
zoneID: CloudKitManager.zoneID
)
- let record = CKRecord(recordType: "PushToken", recordID: recordID)
- record["sessionId"] = sessionId as CKRecordValue
- record["token"] = tokenHex as CKRecordValue
- record["updatedAt"] = Date() as CKRecordValue
do {
+ // Fetch existing record or create new one (upsert)
+ let record: CKRecord
+ do {
+ record = try await CloudKitManager.shared.database.record(for: recordID)
+ } catch {
+ record = CKRecord(recordType: "PushToken", recordID: recordID)
+ }
+ record["sessionId"] = sessionId as CKRecordValue
+ record["token"] = tokenHex as CKRecordValue
+ record["updatedAt"] = Date() as CKRecordValue
_ = try await CloudKitManager.shared.database.save(record)
logger.info("Saved push token to CloudKit for \(sessionId)")
} catch {
diff --git a/Codync-iOS/Services/PremiumManager.swift b/Codync-iOS/Services/PremiumManager.swift
index 5fbb4108..8edc0c55 100644
--- a/Codync-iOS/Services/PremiumManager.swift
+++ b/Codync-iOS/Services/PremiumManager.swift
@@ -9,18 +9,20 @@ private let logger = Logger(subsystem: "com.pokai.Codync.ios", category: "Premiu
final class PremiumManager {
static let shared = PremiumManager()
+ fileprivate(set) var isPro = false
+ private(set) var isLoaded = false
+
#if DEBUG
- /// Flip to `true` to test APNs push without a real subscription
- fileprivate(set) var isPro = true
+ /// When true, isPro is forced on and RevenueCat status is ignored
+ fileprivate let debugForcesPro = true
#else
- fileprivate(set) var isPro = false
+ fileprivate let debugForcesPro = false
#endif
- private(set) var isLoaded = false
private init() {}
func configure() {
- Purchases.logLevel = .verbose
+ Purchases.logLevel = .warn
Purchases.configure(withAPIKey: "REVENUECAT_API_KEY_REDACTED")
Purchases.shared.delegate = RCPurchasesDelegate.shared
Task {
@@ -29,6 +31,12 @@ final class PremiumManager {
}
func refreshStatus() async {
+ if debugForcesPro {
+ isPro = true
+ isLoaded = true
+ logger.info("Premium status: Pro (debug forced)")
+ return
+ }
do {
let info = try await Purchases.shared.customerInfo()
isPro = info.entitlements["Codync Pro"]?.isActive == true
@@ -41,6 +49,7 @@ final class PremiumManager {
}
func restorePurchases() async throws {
+ if debugForcesPro { return }
let info = try await Purchases.shared.restorePurchases()
isPro = info.entitlements["Codync Pro"]?.isActive == true
logger.info("Restored purchases: \(self.isPro ? "Pro" : "Free")")
@@ -55,7 +64,9 @@ private final class RCPurchasesDelegate: NSObject, RevenueCat.PurchasesDelegate,
nonisolated func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) {
let isPro = customerInfo.entitlements["Codync Pro"]?.isActive == true
Task { @MainActor in
- PremiumManager.shared.isPro = isPro
+ if !PremiumManager.shared.debugForcesPro {
+ PremiumManager.shared.isPro = isPro
+ }
logger.info("Customer info updated: \(isPro ? "Pro" : "Free")")
}
}
diff --git a/Codync-macOS/Services/APNsPushService.swift b/Codync-macOS/Services/APNsPushService.swift
index 11e5a657..1de30504 100644
--- a/Codync-macOS/Services/APNsPushService.swift
+++ b/Codync-macOS/Services/APNsPushService.swift
@@ -12,7 +12,8 @@ final class APNsPushService {
private let workerURL = URL(string: "https://codync-push.kevin2005ha.workers.dev")!
private let apiSecret = "f1bf65b18870dffc6c28e69d275413e9c08b33010cb652a781106aaaaf99f329"
- private var pushTokens: [String: String] = [:] // sessionId → token hex
+ private(set) var pushTokens: [String: String] = [:] // sessionId → token hex
+ var tokenCount: Int { pushTokens.count }
private var isFetchingTokens = false
private var lastTokenFetch: Date = .distantPast
@@ -89,20 +90,25 @@ final class APNsPushService {
// MARK: - Push Token Sync (from CloudKit)
- func fetchPushTokens() async {
+ func fetchPushTokens(sessionIds: [String] = []) async {
guard !isFetchingTokens else { return }
- guard Date().timeIntervalSince(lastTokenFetch) > 30 else { return }
+ guard Date().timeIntervalSince(lastTokenFetch) > 10 else { return }
isFetchingTokens = true
- lastTokenFetch = Date() // Update even on failure to avoid spamming
+ lastTokenFetch = Date()
defer { isFetchingTokens = false }
- let query = CKQuery(recordType: "PushToken", predicate: NSPredicate(value: true))
+ // Fetch known push token records by ID (query requires indexing; direct fetch doesn't)
+ var allIds = sessionIds
+ if !allIds.contains("__overall__") { allIds.append("__overall__") }
+
+ let recordIDs = allIds.map {
+ CKRecord.ID(recordName: "pushtoken-\($0)", zoneID: CloudKitManager.zoneID)
+ }
+
do {
- let (results, _) = try await CloudKitManager.shared.database.records(
- matching: query, inZoneWith: CloudKitManager.zoneID, resultsLimit: 20
- )
+ let recordResults = try await CloudKitManager.shared.database.records(for: recordIDs)
var tokens: [String: String] = [:]
- for (_, result) in results {
+ for (_, result) in recordResults {
guard case .success(let record) = result,
let sessionId = record["sessionId"] as? String,
let tokenHex = record["token"] as? String else { continue }
@@ -110,13 +116,8 @@ final class APNsPushService {
}
if tokens != pushTokens {
pushTokens = tokens
- if !tokens.isEmpty {
- logger.info("Fetched \(tokens.count) push tokens from CloudKit")
- }
+ logger.info("Fetched \(tokens.count) push tokens from CloudKit")
}
- } catch let error as CKError where error.code == .unknownItem {
- // PushToken record type doesn't exist yet — iOS hasn't saved any tokens
- logger.debug("No PushToken record type in CloudKit yet")
} catch {
logger.warning("Failed to fetch push tokens: \(error)")
}
diff --git a/Codync-macOS/Services/CloudKitSync.swift b/Codync-macOS/Services/CloudKitSync.swift
index 72c7d9d0..6279f4e6 100644
--- a/Codync-macOS/Services/CloudKitSync.swift
+++ b/Codync-macOS/Services/CloudKitSync.swift
@@ -111,7 +111,8 @@ final class CloudKitSync {
}
// Push to APNs via Worker relay for Live Activity background updates
- await APNsPushService.shared.fetchPushTokens()
+ await APNsPushService.shared.fetchPushTokens(sessionIds: sessions.map(\.sessionId))
+ Self.log("APNs tokens: \(APNsPushService.shared.tokenCount)")
// Individual mode: per-session push
for session in toSave {
await APNsPushService.shared.sendUpdate(session: session)