Last active
May 3, 2017 11:35
-
-
Save omarojo/512cf0b18eb6952cc4cb19434a6510a1 to your computer and use it in GitHub Desktop.
Polling with Timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func startPollingComments(){ | |
if let cStream = currentStream, connected == true{ | |
//the code would not continue if its NOT connected. hence the Timer shcedule will not be generated, this stops the polling | |
let stream = cStream as! FBLiveStream | |
stream.getLastComments(completion: { (comments, error) in | |
if (error == nil){ | |
self.onCommentsUpdate?(comments as! [Dictionary<String, Any>]) | |
} | |
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false, block: {timer in | |
self.startPollingComments() | |
}) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment