-
Notifications
You must be signed in to change notification settings - Fork 854
Closed
Description
I have this problem that whenever I tried to emit onJob, it's not working
Got this error whenever I'm trying to emit
Handling event: error with data: (
"Tried emitting onJob when not connected"
)
As far as I concerned I already connect it in delegate
Here is the code
import UIKit
import SocketIOClientSwift
class SocketIOManager: NSObject {
static let sharedInstance = SocketIOManager()
let socket = SocketIOClient(socketURL: NSURL(string: "https://testing.herokuapp.com")!, options: [.Log(true), .ForcePolling(true)])
override init() {
super.init()
}
func establishConnection() {
socket.connect()
}
func closeConnection() {
socket.disconnect()
}
func onJob(lat: String, long: String) {
socket.emit("onJob", lat, long)
}
}
in app delegate
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
SocketIOManager.sharedInstance.establishConnection()
}
in a view controller
Whenever someone presses a button then socket will emit to the server
SocketIOManager.sharedInstance.onJob("12", long: "12")
Metadata
Metadata
Assignees
Labels
No labels