Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

LiveQueryErrors.InvalidJSONError #43

Closed
@JustinDMoore

Description

@JustinDMoore

Running latest versions of parse server and iOS SDK.

Server setup:

  liveQuery: {
    classNames: ["ChatRooms", "ChatMessages"]
  }

ChatRooms.swift

    let liveQueryClient = ParseLiveQuery.Client()
    private var subscription: Subscription<PChatRoom>?

    var chatRoomsQuery: PFQuery {
        if isPrivate {
            return (PChatRoom.query()?
                .whereKey("name", containsString: PUser.currentUser()?.objectId)
                .whereKey("private", equalTo: true)
                .whereKey("belongsToUser", equalTo: PUser.currentUser()!)
                .orderByDescending("createdAt"))!
        } else {
            return (PChatRoom.query()?
                .whereKey("isPrivate", equalTo: false)
                .orderByDescending("createdAt"))!
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        getExistingRooms()
        subscribeToUpdates()
    }

    func subscribeToUpdates() {
          subscription = liveQueryClient
            .subscribe(chatRoomsQuery)
            .handle(Event.Created) { _, room in
                self.addRoom(room)
        }
    }

    func getExistingRooms() {
        chatRoomsQuery.findObjectsInBackground().continueWithBlock() { task in
            if let chatRooms = task.result as? [PChatRoom] {
                for room in chatRooms {
                    self.arrayOfChatRooms.append(room)
                }
                self.tableView.reloadData()
            }
            return nil
        }
    }

Messages.swift

    let liveQueryClient = ParseLiveQuery.Client()
    private var subscription: Subscription<PChatMessage>?

    var chatQuery: PFQuery {
        if isPrivate {
            return (PChatMessage.query()?
                .whereKey("room", equalTo: room)
                .whereKey("private", equalTo: true)
                .whereKey("belongsToUser", equalTo: PUser.currentUser()!)
                .orderByDescending("createdAt"))!
        } else {
            return (PChatMessage.query()?
                .whereKey("isPrivate", equalTo: false)
                .whereKey("room", equalTo: room)
                .orderByDescending("createdAt"))!
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        getExistingMessages()
        subscribeToUpdates()
    }

    func getExistingMessages() {
        chatQuery.findObjectsInBackground().continueWithBlock() { task in
            if let chatLog = task.result as? [PChatMessage] {
                for message in chatLog {
                    self.addMessage(message.author.objectId!, text: message.message)
                }
                self.finishReceivingMessage()
            }
            return nil
        }
    }

    func subscribeToUpdates() {
        subscription = liveQueryClient
            .subscribe(chatQuery)
            .handle(Event.Created) { _, message in
                self.incomingMessage(message)
        }
    }

Nearly identical liveQueries in both classes.
ChatRooms.swift works fine and receives live updates.
When calling subscribe in Messages.swift, the console outputs only "140725914386528"
and breakpoints at throw LiveQueryErrors.InvalidJSONError(json: json, expectedKey: key) in Operation.swift

        func jsonValue<T>(json: [String:AnyObject], _ key: String) throws -> T {
            guard let value =  json[key] as? T
                else {
                    **throw LiveQueryErrors.InvalidJSONError(json: json, expectedKey: key)**
            }
            return value
        }

What might be causing this to be thrown?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions