ios


add observe to json file if there's new data


Well I'm try to build simple chat that receive the message from JSON file
So I think that I should update my function every second to check if there is new message or not, but I think this is not right because it increases the amount of useless request.
This is my code
I use these libraries
import Alamofire
import SwiftyJSON
This is my function
func didchat(){
Alamofire.request(.GET, "http://www.elofight.com/test.json").responseJSON { (responseData) -> Void in
self.reciveResponse = JSON(responseData.result.value!)
print(self.reciveResponse)
}
}
and this is my function that call this json file every 1 sec
override func viewDidLoad() {
super.viewDidLoad()
NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewChatViewController.didchat), userInfo: nil, repeats: true)
}
any suggest for that ?
You should set a minimum time interval as you did, and it's correct.
Or you can use Firebase, it does exactly what you mean: you can set your object as listener on the database and you can do something when this happens.
Here you can find a chat-app example by Firebase guys: https://github.com/firebase/ios-swift-chat-example

Related Links

Generic UIView confirmable function in Swift
How to rotate APP delegate window's label in ios?
Multipeer Connectivity and data to send along the way
XCode iOS UISlider - Custom Scaling Min and Max
Linking problems when creating a library for iOS 7
UIAlertController - iOS 8 - iPad - Not Centering Properly
NSArray not finishing before TableView call?
Retrieving data from parse in NSMutable array and then get the data from the cells where the button has been tapped
UIImage Distortion from UIGraphicsBeginImageContext with larger files (pixel formats, codecs?)
iOS unit tests crashing randomly on Jenkins with no backtrace
iOS: Terminating app due to uncaught exception 'NSRangeException'
How to transition to Emoji keyboard from Custom Keyboard when nextKeyboard is pressed
fatal error after reloadData UITableView in other class
How to lock navigation and tab bars?
App Delegate - Load Core Data Swift
How to stop music in a SpriteKit game from another class

Categories

HOME
redirect
clojure
gwt
codenameone
performance-testing
configuration
haskell-stack
anylogic
backand
windows-server-2012-r2
spacemacs
whitespace
jena
eloqua
nservicebus
avr
round-robin
org-mode
silk-performer
smartcard
jmeter-plugins
sax
burp
padding
desktop-app-converter
ucwa
trial
flatbuffers
nest-thermostat
complex-networks
gridstack
extraction
joe-editor
runge-kutta
runc
psychopy
mdanalysis
projection
angularjs-routing
xargs
win2d
phasset
invalidate
html-form
infiniband
tastypie
blocking
vistadb
tachyon
tealeaf
hyperterm
rras
namenode
main-activity
id3
mysqladmin
document-ready
readline
sample-data
android-gpuimageview
wt
tabbar
dhc
simperium
byte-order-mark
lossless-compression
swift-array
httpservice
email-spam
dirpagination
serverside-javascript
freemind
siblings
zephir
wow64
headless-browser
documentviewer
ariatemplates
noindex
molehill
cellphone
payment-services
mdi
process.start
eye-detection
directoryentry
orthographic
nstreecontroller
alivepdf
noaa
seam-conversation
msn-messenger
run-length-encoding
resharper-4.5

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App