1

I am writing an iOS (Swift) application that includes the ability to send messages between users. I have that functionality working (using JSQMessagesViewController), but I don't know where to start with auto updating. If the user is in the messaging screen and receives a new message, I need a way for it to show up. Here are a couple thoughts:

  • Use a timer, and check for new messages every specified interval. This seems very battery & data intensive.
  • Use Parse Push notifications. I'm not sure if you can do this or not.

Any guidance would be greatly appreciated.

Robert
  • 1,499
  • 2
  • 14
  • 22

1 Answers1

0

There is a full tutorial on this here

class ViewController: JSQMessagesViewController, SyncanoSyncServerDelegate 
{
   // MARK: - Server delegate methods
    func syncServerConnectionOpened(syncServer: SyncanoSyncServer!) {
        self.subscribeToCollection()
    }

    func syncServer(syncServer: SyncanoSyncServer!, connectionClosedWithError error: NSError!) {
        self.syncServer.connect(nil);
    }

    func syncServer(syncServer: SyncanoSyncServer!, notificationAdded addedData: SyncanoData!, channel: SyncanoChannel!) {
       if let senderId = addedData.additional?["senderId"] as? String {
           let message = JSQMessage(senderId: senderId, displayName: senderId, text: addedData.text)
           self.messages += [message]
       }
       self.finishReceivingMessage()
    }

    override func viewDidLoad(){
        super.viewDidLoad()
        self.syncServer.delegate = self
        self.syncServer.connect(nil);
    }
}
Lukas
  • 3,423
  • 2
  • 14
  • 26