Live query not working in iOS code

@ashish-naik Ashish
Mon, 22 Sep 2025 18:33:31 +0000

I am running parse server on local macOS. Server URL is is http://192.168.1.2:1337/parse. Parse server and live server are configured properly : class names are added.websocket is working fine. Testing from Terminal using wscat. Parse object being updated has read access for logged in PFUser. websocket trace or log is not printed in Xcode console. LiveQuerymanager instance is stored in app delegate and available through app. it is instantiated after Parse server is configured. Parse Server version 7.3, iOS SDk v5.1.1

this is the code

import ParseLiveQuery
import ParseCore
class LiveQueryManager {
    static let shared = LiveQueryManager()

    private var client: ParseLiveQuery.Client
    private var TestObjectSubscription: Subscription<PFObject>?
    let TestObjectQuery = PFQuery(className: "TestObject")

    init() {

        client = ParseLiveQuery.Client(
            server: "http://192.168.2.1:1337",
            applicationId: "parseAppID",
            clientKey: "parseClientID"
        )
        client.shouldPrintWebSocketLog = true
        client.shouldPrintWebSocketTrace = true

        TestObjectSubscription = client.subscribe(TestObjectQuery) //client.subscribe(query)
        TestObjectSubscription!.handle(Event.created) { _, book in

            if let title = book["title"] as? String, let id = book.objectId {
                print("Book \(title) was added")
            }
        }

        TestObjectSubscription!.handle(Event.updated) { _, book in
            if let title = book["title"] as? String, let id = book.objectId {
                print("Book \(title) was updated")
            }
        }

        TestObjectSubscription!.handle(Event.deleted) { _, book in

            if let title = book["title"] as? String, let id = book.objectId {
                print("Book \(title) was deleted")
            }
        }

        TestObjectSubscription!.handleSubscribe { query in
            print("TestObject subscription status changed to \(query)")
        }

        TestObjectSubscription!.handleSubscribe { TestObjectQuery in
            print("Subscribed to Live Query for TestObject updates")
        }

        TestObjectSubscription!.handle(LiveQueryErrors.InvalidJSONError.self) { query, error in
            print("InvalidJSONError  \(error)")
         }

        TestObjectSubscription!.handle(LiveQueryErrors.InvalidResponseError.self) { query, error in
            print("InvalidResponseError  \(error)")
         }
        TestObjectSubscription!.handle(LiveQueryErrors.InvalidQueryError.self) { query, error in
            print("InvalidQueryError \(error)")
         }

        TestObjectSubscription!.handle(LiveQueryErrors.InvalidJSONObject.self) { query, error in
            print("InvalidJSONObject \(error)")
         }

        TestObjectSubscription!.handle(LiveQueryErrors.ServerReportedError.self) { query, error in
            print("ServerReportedError \(error)")
            self.client.reconnect()
         }


        ParseLiveQuery.Client.shared = client



    }
}