Skip to content

Handling event error #379

@arashdoescode

Description

@arashdoescode

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions