Unsubscribe from events in iOS


#1

I hope this question seems easy for someone.

What should I put in the ‘eventListenerID’?

if let sid = eventListenerID {
    SparkCloud.sharedInstance().unsubscribeFromEvent(withID: sid)
}

#2

The ID you received from:

var eventListenerID : Any?
eventListenerID = SparkCloud.sharedInstance().subscribeToMyDevicesEvents(withPrefix: “temp”, handler: handler)

(or similar method, there are others returning eventListenerID). Or if you want to chuck out all subscriptions:

SparkCloud.sharedInstance().unsubscribeFromEvent(withID: “”)


#3

Thanks a lot! I’ve only used this code earlier so I’ve not thought about the ‘eventListenerID’:

var handler : Any?
handler = SparkCloud.sharedInstance().subscribeToAllEvents(withPrefix: "temp", handler: { (event :SparkEvent?, error : Error?) in
    if let _ = error {
        print ("could not subscribe to events")
    } else {
        DispatchQueue.main.async(execute: {
            print("got event with data \(event?.data)")
        })
    }
})