Rawan Rawan - 1 year ago 156
Swift Question

How to know if Unsubscribe channels request in Pubnub is success?

I'm trying to unsubscribe PubNub channels when I logged out from my app, like this way


My problem is that I can't be sure that unsubscribe channels process is success or NOT!

there is no completion handler for error, success.

So my question is how can I be sure from unsubscribe channels process?


I send Push notification in my Pubnub channel, so I want after the user logged out to never get push notification anymore, so I decided to unsubscribe the channel, but it seems that


doesn't work, because I still get push notification although I logged out from my app, so do you know how to unsubscribe PubNub channel so I won't get push notification after I logged out from my app ?

Answer Source

To figure this out you should use same callback which is used by delegate to track client state change like this:

func client(client: PubNub!, didReceiveStatus status: PNSubscribeStatus!) {

    if status.operation == .UnsubscribeOperation {

        if !status.error { /* Handle successful unsubscription. */ }
        else { /* Handle unsubscription error. */ }

Callbacks in case of: state change, presence and message arrival used because potentially few observers would like to know about this. Other operation usually context-based and completion block is more than enough in those cases.

Best regards, Sergey

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download