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

iOS, Swift: “Unable to simultaneously satisfy constraints” in syslog
Bit rate values for iOS mp3 (AVaudioPlayer)
How do I implement Floating Action Button in iOS?
Subclass or Protocol, How to?
AVCaptureSession with Autolayout
React-native#0.26.3 requires a peer of react#15.0.2 but none was installed
Caught NSInternalInconsistencyException request for rect at invalid indexPath
Unable to store facebook user data in google firebase
My App is getting Crash stating index 21 beyond bounds [0 .. 19]' *** First throw call stack:
Getting rotation event of UICollectionViewController inside a UITableViewCell
didcompletewitherror return nil even for request with bad url
iOS: is it possible to programmatically read the phone battery percentage?
UIImageView image not updating when in tableviewcell
Remove current ViewController after instantiate and presented the next VC
ionic / firebase ipv6 Auth ios app rejection
How can we read the value of registers/coils connected to a modbus connection in objective-c

Categories

HOME
odoo-10
printing
hortonworks-data-platform
blogs
stack
delphi-xe7
spacemacs
microsoft-dynamics
clion
drag
h2o
research
pymc3
eloqua
pouchdb
zend-expressive
accumulo
records
oracle11gr2
abaqus
smartcard
nintex-workflow
code-analysis
microphone
precision
structure
x-sendfile
asana-api
angular2-databinding
nest-thermostat
pyparsing
mobilefirst-bluemix
dashboard-designer
capstone
haxm
edit-distance
chamilo-lms
titanium-alloy
joe-editor
bem
extjs4
polymer-cli
rating
backwards-compatibility
keyboard-maestro
simplesamlphp
ssms-2012
sql-mode
fido
htc
libev
kony
ice
gpt
jcuda
asp.net-mvc-custom-filter
replicate
turbo-c
android-sdk-tools
django-errors
mailcore2
sound-synthesis
mit-scheme
building
coldfusion-11
data-fitting
balsamiq
python-3.1
jstorm
isapi-rewrite
vsvim
rabbitvcs
facebook-comments
aplpy
jni4net
parsoid
actioncable
python-dragonfly
interpreted-language
selectsinglenode
boost-coroutine
wintersmith
jet.com-apis
lwuit-list
globus-toolkit
aps
requiredfieldvalidator
modalpopupextender
dotliquid
angularjs-google-maps
antisamy
array-address
resolver
pligg
nsusernotificationcenter
glulookat
pubdate
capitalize
mosek
uptime
word-2010
android-actionbar-compat
ms-access-97
letter-spacing
blackberry-jde
custom-tag
renderaction
jquery-1.3.2
noaa
keylogger
xml-database
drupal-gmap
resharper-4.5
templatebinding
variable-names

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