ios - Getting Data from server Continuosly -
i need data server continuously. have searched , came thought of calling service in background thread continuously in particular time interval using nstimer.
var timer = nstimer.scheduledtimerwithtimeinterval(10, target: self, selector: "callservice", userinfo: nil, repeats: true) func callservice() { let qualityofserviceclass = qos_class_background let backgroundqueue = dispatch_get_global_queue(qualityofserviceclass, 0) dispatch_async(backgroundqueue, { ..... dispatch_async(dispatch_get_main_queue(), { () -> void in ...... }) }) }
can this?. way this? or there other way this? want know how didupdatelocation
in cllocationmanagerdelegate
works. want implement similar approach that. please give idea in this.
i acheived through socket.io. saw site http://geoloqi.com/blog/2011/09/building-a-real-time-location-based-urban-geofencing-game-with-socket-io-redis-node-js-and-sinatra-synchrony/#comments. when go through link, understand did same me using nstimer call service @ particular time interval. used great battery power. used socket.
i got socket.io code swift 2 github https://github.com/socketio/socket.io-client-swift
let socket = socketioclient(socketurl: "localhost:8080") socket.on("connect") {data, ack in print("socket connected") } socket.on("currentamount") {data, ack in if let cur = data[0] as? double { socket.emitwithack("canupdate", cur)(timeoutafter: 0) {data in socket.emit("update", ["amount": cur + 2.50]) } ack?.with("got currentamount", "dude") } } socket.connect()
it solved question.
Comments
Post a Comment