T
T
tupoi2017-07-16 17:11:07
iOS
tupoi, 2017-07-16 17:11:07

How to make the application "follow" events constantly?

Good day, I'm trying to write a small chat, on the server I use node.js and socket.io, on the client (ios) Swift and the SocketIOClient library. On the server, I implemented sending, receiving messages, authorization, connect and disconnect, and on the client there was a problem, I can’t figure out how to listen to events all the time. I created a singleton, implemented all the methods related to the work of socket.io in it, it sends data and they come to the server, the server sends them to the same socket id, but my device no longer accepts them. How to implement "surveillance" of these events? Can use Observer? or a separate thread that will spin in a loop and check (but this is some kind of collective farm already fierce)? Can anyone suggest which way to look? Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AzamatBolegenov, 2017-07-18
@AzamatBolegenov

Do it through push notifications. I don't know anything else to access the app when it's inactive

A
Anton Gorb, 2017-07-19
@AntonGorb

On a server

var app = require('express')()
var server = require('http').Server(app)
var io = require('socket.io')(server)

server.listen(3000)

io.on('connection', function(socket) {
  socket.on('comment', function(data) {
    io.emit('comment', data)
  })
}

On the client
socket.on("comment") {[weak self] data ,ack in
// получаешь комменты
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question